Skip to content

Exceptions

These exception classes are used in client implementations.

Base

ApplicationError

Base class for all exceptions raised by Horizon.

message

Message string

details

Details related to specific error

Authorization

AuthorizationError

Authorization request is failed.

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

message

details

Permissions

PermissionDeniedError

Permission denied for performing the requested action.

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.

message

details

required_role = required_role

Required role to perform action

actual_role = actual_role

Actual user role

BadRequestError

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 = reason

Bad request reason message

Entity

EntityNotFoundError

Entity not found.

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

message

details

entity_type = entity_type

Entity type

field = field

Entity identifier field

value = value

Entity identifier value

EntityAlreadyExistsError

Entity with same identifier already exists.

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

message

details

entity_type = entity_type

Entity type

field = field

Entity identifier field

value = value

Entity identifier value

Service

ServiceError

Service used by application have not responded properly.

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

message