Skip to content

Add error serde to http-binding client protocols #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

haydenbaker
Copy link
Contributor

Description of changes:

  • Adds error serde and handling in http binding client protocols
    • Adds amzn header extractor and adds it to the rest json client protocol
  • Adds new exceptions, CallException and ModeledException, which are meant to be used when code-generating the error shapes

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@haydenbaker haydenbaker requested a review from a team as a code owner March 25, 2025 01:04
Comment on lines +11 to +14
def get_error(self, response: HTTPResponse):
if "x-amzn-errortype" in response.fields:
val = response.fields["x-amzn-errortype"].values[0]
return ShapeID(val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will be enough. This can show up in a few other headers and has several formats which may or may not include a namespace. I could also be in the body.



@dataclass(kw_only=True, frozen=True)
class CallException(RuntimeError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All exceptions we define should inherit from SmithyException


from smithy_core.deserializers import DeserializeableShape

type Fault = Literal["client", "server", "other"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other?

message: str = ""
"""The error message."""

# TODO: retry-ability and associated information (throttling, duration, etc.), perhaps 'Retryability' dataclass?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah having a RetryableException protocol, mixin, or something would be ideal. Classifying is too complex without embedding the information in the exception.


def get_error(
self,
response: HTTPResponse,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be tied to HTTP

def get_error(
self,
response: HTTPResponse,
) -> ShapeID | None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might actually be the place to get the retry info

Comment on lines +301 to +302
deserializer = self._payload_codec.create_deserializer(body)
document = deserializer.read_document(DOCUMENT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can errors have streaming payloads? (blob streams that is)

)

# return the deserialized error
return error_shape.deserialize(deserializer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to rewind the body since you've already read from it

Comment on lines +307 to +309
# if none, get it from the parsed document (e.g. '__type')
if error_id is None:
error_id = document.discriminator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're getting this document from the payload codec, but that's not necessarily gonna give you what you want. Different JSON protocols could embed this differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants