Skip to content

Enhance session's error parse method #388

@Kamforka

Description

@Kamforka

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions