patera.exceptions¶
HTTP exceptions and exception handlers. See the exception handling guide.
Exceptions submodule
ExceptionHandler
¶
Bases: Injectable, Generic[AppT]
get_exception_mapping
¶
Maps each handled exception class to its handler method.
BaseHttpException
¶
BaseHttpException(message: str = '', status_code: int | HttpStatus = 500, status='error', data=None)
Bases: Exception
Base http exception class
Init method
RequestValidationError
¶
RequestValidationError(validation_error: ValidationError, message: str = 'Validation failed', status_code: int = 422, status: str = 'error')
Bases: BaseHttpException
Raised when @consumes cannot build the declared model from the request
body. Answered with 422 Unprocessable Content; data (and errors)
lists each problem's location, message and type. The submitted values are
left out, so a rejected password is never sent back.
The original Pydantic error is validation_error. A ValidationError
raised anywhere else (in handler code, or validating data from a database
or another service) is a server error, answered with 500.
InvalidRequestBody
¶
InvalidRequestBody(message: str = 'Malformed request body', status_code: int = 400, status: str = 'error', data: Any = None)
Bases: BaseHttpException
Raised when a request body cannot be parsed, such as malformed JSON. Answered with 400 Bad Request.
RequestBodyTooLarge
¶
RequestBodyTooLarge(max_content_length: int, message: str = 'Request body too large', status_code: int = 413, status: str = 'error')
Bases: BaseHttpException
Raised when a request body is larger than the allowed maximum. Answered with 413 Content Too Large.
AborterException
¶
StaticAssetNotFound
¶
StaticPageNotFound
¶
ClientDisconnected
¶
Bases: CustomException
Raised when the client disconnects before its request body has arrived completely. The handler is stopped (and a transaction rolled back), and no response is sent, since nobody is left to receive it.
CustomException
¶
Bases: Exception
Base custom exception class
DuplicateRouteError
¶
Bases: CustomException, ValueError
Raised when two different handlers are registered for the same HTTP method and path.
CircularDependencyError
¶
Bases: CustomException, RuntimeError
Raised when injected dependencies require each other in a cycle.
MethodNotControllerMethod
¶
UnexpectedDecorator
¶
abort
¶
abort(msg: str, status_code: int | HttpStatus = BAD_REQUEST, status: str = 'error', data: Any = None)
Aborts request by raising an aborter exception
html_abort
¶
html_abort(template: str, status_code: int | HttpStatus = BAD_REQUEST, data: Any = None)
Aborts request with html response