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

Enhance session's error parse method #388

Closed
Kamforka opened this issue Feb 6, 2025 · 0 comments · Fixed by #393
Closed

Enhance session's error parse method #388

Kamforka opened this issue Feb 6, 2025 · 0 comments · Fixed by #393

Comments

@Kamforka
Copy link
Collaborator

Kamforka commented Feb 6, 2025

The error response parser at the moment is a naively considering any json response to be a standard TheHive error response:

    def _process_error_response(self, response: requests.Response):
        try:
            json_data = response.json()
        except requests.exceptions.JSONDecodeError:
            json_data = None

        if json_data is None:
            error_text = response.text
        else:
            error_text = f"{json_data['type']} - {json_data['message']}"
        raise TheHiveError(message=error_text, response=response)

To fix this it might be more reasonable to do something like:

    def _process_error_response(self, response: requests.Response):
        try:
            json_data = response.json()
        except requests.exceptions.JSONDecodeError:
            json_data = None

        if isinstance(json_data, dict) and all(["type" in json_data, "message" in json_data]):
            error_text = f"{json_data['type']} - {json_data['message']}"
        else:
            error_text = response.text
        raise TheHiveError(message=error_text, response=response)
@Kamforka Kamforka added this to the 2.0.0b9 milestone Feb 6, 2025
@Kamforka Kamforka linked a pull request Feb 16, 2025 that will close this issue
Kamforka added a commit that referenced this issue Feb 16, 2025
…or-parse-method

#388 - Enhance session's error parse method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant