@@ -51,7 +51,7 @@ def handler(event: MyBusiness , context: LambdaContext):
5151 Raises
5252 ------
5353 SchemaValidationError
54- When input event doesn't conform with schema provided
54+ When input event does not conform with schema provided
5555 InvalidSchemaTypeError
5656 When schema given does not implement BaseModel
5757 """
@@ -92,23 +92,25 @@ def handler(event: MyBusiness , context: LambdaContext):
9292 Raises
9393 ------
9494 SchemaValidationError
95- When input event doesn't conform with schema provided
95+ When input event does not conform with schema provided
9696 InvalidSchemaTypeError
9797 When schema given does not implement BaseModel
98-
98+ InvalidEnvelopeError
99+ When envelope given does not implement BaseEnvelope
99100 """
100- if envelope :
101+ if envelope and callable ( envelope ) :
101102 try :
102- logger .debug (f"Parsing and validating event schema, envelope={ envelope } " )
103- # noinspection PyCallingNonCallable
103+ logger .debug (f"Parsing and validating event schema with envelope={ envelope } " )
104104 return envelope ().parse (event = event , schema = schema )
105- except (TypeError , AttributeError ):
106- raise InvalidEnvelopeError (f"envelope must be a callable and instance of BaseEnvelope, envelope={ envelope } " )
105+ except AttributeError :
106+ raise InvalidEnvelopeError (f"Envelope must implement BaseEnvelope, envelope={ envelope } " )
107+ except (ValidationError , TypeError ) as e :
108+ raise SchemaValidationError (f"Input event does not conform with schema, envelope={ envelope } " ) from e
107109
108110 try :
109111 logger .debug ("Parsing and validating event schema; no envelope used" )
110112 return schema .parse_obj (event )
111113 except (ValidationError , TypeError ) as e :
112- raise SchemaValidationError ("Input event doesn't conform with schema" ) from e
114+ raise SchemaValidationError ("Input event does not conform with schema" ) from e
113115 except AttributeError :
114116 raise InvalidSchemaTypeError ("Input schema must implement BaseModel" )
0 commit comments