Exceptions¶
These exception classes are used in client implementations.
Base¶
Permissions¶
- class horizon.commons.exceptions.permission.PermissionDeniedError(required_role: str, actual_role: str)¶
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.
- 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.
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.
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:
messageMessage 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