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

Persist error response data in TheHiveError #258

Merged
merged 1 commit into from
Oct 21, 2022

Conversation

Kamforka
Copy link
Collaborator

This one is a convenience feature to better handle exceptions due to API errors.

At the moment one only has access to the parsed error message of an exception, e.g.:

try:
    ...
except TheHiveError as err:
    if "CreateError" in str(err):
        print("handle create errors here")
    else:
        print("do generic error handling here")

From the above it is clear that the handling capabilities are limited to the parsed error string, while with this change one can do:

try:
    ...
except TheHiveError as err:
    if "CreateError" in err.message:
        print("handle create errors here")
    else:
        if err.response:
            if err.response.status_code == 401:
                print("handle authentication error here")
            else:
                # do anything generic with the error response here
                error_json = err.response.json()

@Kamforka Kamforka merged commit eb0a562 into develop Oct 21, 2022
@Kamforka Kamforka deleted the persist-response-data-in-exception branch October 27, 2022 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants