Exceptions

These exception classes are used in client implementations.

Base

class horizon.commons.exceptions.base.ApplicationError

Base class for all exceptions raised by Horizon.

Attributes:
details

Details related to specific error

message

Message string

abstract property details: Any

Details related to specific error

abstract property message: str

Message string

Authorization

class horizon.commons.exceptions.auth.AuthorizationError(message: str, details: Any = None)

Authorization request is failed.

Attributes:
details

Details related to specific error

message

Message string

Examples

>>> from horizon.commons.exceptions import AuthorizationError
>>> raise AuthorizationError("User 'test' is disabled")
Traceback (most recent call last):
horizon.commons.exceptions.auth.AuthorizationError: User 'test' is disabled
property details: Any

Details related to specific error

property message: str

Message string

Permissions

class horizon.commons.exceptions.permission.PermissionDeniedError(required_role: str, actual_role: str)

Permission denied for performing the requested action.

Attributes:
details

Details related to specific error

message

Message string

Examples

>>> from horizon.commons.exceptions import PermissionDeniedError
>>> raise PermissionDeniedError(required_role="DEVELOPER", actual_role="GUEST")
Traceback (most recent call last):
horizon.commons.exceptions.PermissionDeniedError: Permission denied. User has role GUEST but action requires at least DEVELOPER.
required_role: str

Required role to perform action

actual_role: str

Actual user role

property message: str

Message string

property details: dict[str, Any]

Details related to specific error

class horizon.commons.exceptions.bad_request.BadRequestError(reason: str)

Bad request error.

This exception should be raised when a request cannot be processed due to client-side errors (e.g., invalid data, duplicate entries).

Examples

>>> from horizon.commons.exceptions import BadRequestError
>>> raise BadRequestError("Duplicate username detected. Each username must appear only once.")
Traceback (most recent call last):
horizon.commons.exceptions.BadRequestError: Duplicate username detected. Each username must appear only once.
reason: str

Bad request reason message

Entity

class horizon.commons.exceptions.entity.EntityNotFoundError(entity_type: str, field: str, value: Any)

Entity not found.

Attributes:
details

Details related to specific error

message

Message string

Examples

>>> from horizon.commons.exceptions import EntityNotFoundError
>>> raise EntityNotFoundError("User", "username", "test")
Traceback (most recent call last):
horizon.commons.exceptions.entity.EntityNotFoundError: User with username='test' not found
entity_type: str

Entity type

field: str

Entity identifier field

value: Any

Entity identifier value

property message: str

Message string

property details: dict[str, Any]

Details related to specific error

class horizon.commons.exceptions.entity.EntityAlreadyExistsError(entity_type: str, field: str, value: Any)

Entity with same identifier already exists.

Attributes:
details

Details related to specific error

message

Message string

Examples

>>> from horizon.commons.exceptions import EntityNotFoundError
>>> raise EntityAlreadyExistsError("User", "username", "test")
Traceback (most recent call last):
horizon.commons.exceptions.entity.EntityAlreadyExistsError: User with username='test' already exists
entity_type: str

Entity type

field: str

Entity identifier field

value: Any

Entity identifier value

property message: str

Message string

property details: dict[str, Any]

Details related to specific error

Service

class horizon.commons.exceptions.service.ServiceError(message: str)

Service used by application have not responded properly.

Attributes:
message

Message string

Examples

>>> from horizon.commons.exceptions import ServiceError
>>> raise ServiceError("Some server response is invalid")
Traceback (most recent call last):
horizon.commons.exceptions.service.ServiceError: Some server response is invalid
property message: str

Message string