Skip to content
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

HTTP Status Errors: enrich-and-reraise #309

Merged
merged 3 commits into from
Aug 28, 2024

Conversation

hemidactylus
Copy link
Collaborator

This PR introduces a new astrapy exception in the class hierarchy, DataAPIHttpException, sibling to DataApiResponseException.

The new one represents 4xx/5xx responses from the API. Since in some cases these responses still contain useful info in the standard {"errors": [...]} format, which would be omitted in string representation of the httpx exception, now astrapy does the following:

  • catches 4xx and 5xx exceptions as httpx errors
  • repackages them as DataAPI exceptions, enriching them with the "error descriptors" as it does for "response exceptions" already;
  • raises them.

Note that the new error class (see pictures/astrapy_exceptions.png) inherits from both DataAPIException and the httpx class: this, while not presenting relevant "diamond-type" multiple-inheritance problems, allows current flows based on catching the httpx exceptions to continue working.

text: Optional[str],
*,
httpx_error: httpx.HTTPStatusError,
error_descriptors: List[DataAPIErrorDescriptor],
Copy link
Collaborator

@erichare erichare Aug 28, 2024

Choose a reason for hiding this comment

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

Should this be Optional here? error_descriptors: Optional[List[DataAPIErrorDescriptor]]

Just judging by the attribute default

Choose a reason for hiding this comment

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

Wouldn't [] convey the same information as Nothing? (in this context)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree; and agree.
The Optional was an oversight from me, sorry and thank you for spotting this!
In line with the counterpart exception (DataAPIResponseException), there's no Optional and it is [] if nothing.

thanks!

@hemidactylus hemidactylus merged commit 550c208 into master Aug 28, 2024
3 checks passed
@hemidactylus hemidactylus deleted the SL-500-augmented-reraiser branch August 28, 2024 17:16
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.

3 participants