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
Fix exception handling in ApiMethodWrapper.handle_neptune_http_errors
#1469
Conversation
ApiMethodWrapper.handle_neptune_http_errors
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
src/neptune/api/exceptions_utils.py
Outdated
raise default_exception from source_exception | ||
raise source_exception | ||
|
||
if isinstance(source_exception, BaseException): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make source_exception
an Optional
(source_exception: Optional[Exception]
) and check if it's not None.
except AttributeError: | ||
pass | ||
|
||
if exception is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
seems to be unnecessary.
|
||
if exception is None: | ||
# raise generic HTTPError with response info | ||
raise HTTPError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't expose bravado exceptions. ;)
How about using NeptuneApiException
?
src/neptune/api/exceptions_utils.py
Outdated
@@ -35,8 +35,8 @@ def handle_json_errors( | |||
if error_processor: | |||
raise error_processor(content) from source_exception | |||
|
|||
if default_exception and isinstance(source_exception, BaseException): | |||
if default_exception and source_exception is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still may want to raise a default_exception
. Just without a cause (from
).
@aniezurawski
They have 422 and 402 codes. |
message=f"{response.status_code} Error: {response.reason} for {response.url}", response=response | ||
) | ||
# raise generic NeptuneApiException with response info | ||
raise NeptuneApiException(f"{response.status_code} Error: {response.reason} for {response.url}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again let's wrap it in exept AttributeError
and just stringify all arguments if somthing goes wrong.
Huh. Good point. In this case it look like |
I don't follow. What's then the point of calling this with |
…tune_http_errors
Before submitting checklist