Skip to content

Exceptions

flask_restapi.exceptions.ApiException (Exception)

Source code in flask_restapi/exceptions.py
class ApiException(Exception):
    def __init__(self, http_code: int, **options) -> None:
        """HTTP responses with errors to the client

        Args:
            http_code (int): HTTP response status code.
        """
        self.http_code = http_code
        for key, value in options.items():
            setattr(self, key, value)

    def to_dict(self) -> Dict[str, Any]:
        """Convert all attributes to dictionary and exclude http_code of the key.

        Returns:
            All attributes but excluding http_code
        """
        return self.__dict__

    def to_json(self) -> str:
        """Convert all attributes to json and exclude http_code of the key.

        Returns:
            All attributes but excluding http_code
        """
        return json.dumps(self.__dict__)

__init__(self, http_code, **options) special

HTTP responses with errors to the client

Parameters:

Name Type Description Default
http_code int

HTTP response status code.

required
Source code in flask_restapi/exceptions.py
def __init__(self, http_code: int, **options) -> None:
    """HTTP responses with errors to the client

    Args:
        http_code (int): HTTP response status code.
    """
    self.http_code = http_code
    for key, value in options.items():
        setattr(self, key, value)

to_dict(self)

Convert all attributes to dictionary and exclude http_code of the key.

Returns:

Type Description
Dict[str, Any]

All attributes but excluding http_code

Source code in flask_restapi/exceptions.py
def to_dict(self) -> Dict[str, Any]:
    """Convert all attributes to dictionary and exclude http_code of the key.

    Returns:
        All attributes but excluding http_code
    """
    return self.__dict__

to_json(self)

Convert all attributes to json and exclude http_code of the key.

Returns:

Type Description
str

All attributes but excluding http_code

Source code in flask_restapi/exceptions.py
def to_json(self) -> str:
    """Convert all attributes to json and exclude http_code of the key.

    Returns:
        All attributes but excluding http_code
    """
    return json.dumps(self.__dict__)