Skip to content

Suggestion for new exception type #94

@kwilsonmg

Description

@kwilsonmg

Please describe your feature request.

That the ApiError for status code "forbidden" ("You aren't permitted to perform this request.") have its own exception class inheriting from ApiError so that it can be caught separately more easily.

Describe your solution.

I would suggest that there be a new exception class created that inherits from ApiError that is raised when ApiError is encountered with status code forbidden. Below is a rough somewhat pseudocode of what that could potentially look like, at least as quick way to add this in/illustrate.

class ApiError(HTTPError):
    def __new__(cls, message, error_type=None):
        if error_type == 'forbidden':
            return super().__new__(ForbiddenError)
        return super().__new__(cls)

class ForbiddenError(ApiError):
    pass

Describe alternatives you have considered.

You could catch it through ApiError and handle via checking e.error_code == "forbidden", but it is somewhat cleaner to handle as a different exception type in my opinion.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions