Skip to content

Commit c14a0dd

Browse files
Check unknown error content type before read
This updates the error deserializer to check that the content type of a response matches the protocol's content type before it tries searching the payload for a shape id.
1 parent e831bdf commit c14a0dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/smithy-http/src/smithy_http/aio/protocols.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async def _create_error(
183183
operation=operation, response=response
184184
)
185185

186-
if error_id is None:
186+
if error_id is None and self._matches_content_type(response):
187187
if isinstance(response_body, bytearray):
188188
response_body = bytes(response_body)
189189
deserializer = self.payload_codec.create_deserializer(source=response_body)
@@ -227,3 +227,8 @@ async def _create_error(
227227
is_throttling_error=is_throttle,
228228
is_retry_safe=is_throttle or None,
229229
)
230+
231+
def _matches_content_type(self, response: HTTPResponse) -> bool:
232+
if "content-type" not in response.fields:
233+
return False
234+
return response.fields["content-type"].as_string() == self.content_type

0 commit comments

Comments
 (0)