exception#
- starlite.utils.exception.get_exception_handler(exception_handlers: ExceptionHandlersMap, exc: Exception) Optional[ExceptionHandler] #
Given a dictionary that maps exceptions and status codes to handler functions, and an exception, returns the appropriate handler if existing.
Status codes are given preference over exception type.
If no status code match exists, each class in the MRO of the exception type is checked and the first matching handler is returned.
Finally, if a
500
handler is registered, it will be returned for any exception that isn’t a subclass ofHTTPException
.- Parameters:
exception_handlers – Mapping of status codes and exception types to handlers.
exc – Exception Instance to be resolved to a handler.
- Returns:
Optional exception handler callable.
- class starlite.utils.exception.ExceptionResponseContent#
Bases:
BaseModel
Represent the contents of an exception-response.
- starlite.utils.exception.create_exception_response(exc: Exception) Response #
Construct a response from an exception.
Notes
For instances of
HTTPException
or other exception classes that have astatus_code
attribute (e.g. Starlette exceptions), the status code is drawn from the exception, otherwise response status isHTTP_500_INTERNAL_SERVER_ERROR
.
- Parameters:
exc – An exception.
- Returns:
HTTP response constructed from exception details.
- Return type: