exceptions#

exception litestar.exceptions.ClientException#

Bases: HTTPException

Client error.

status_code: int = 400#

Exception status code.

exception litestar.exceptions.DTOFactoryException#

Bases: LitestarException

Base DTO exception type.

exception litestar.exceptions.HTTPException#

Bases: LitestarException

Base exception for HTTP error responses.

These exceptions carry information to construct an HTTP response.

__init__(*args: Any, detail: str = '', status_code: int | None = None, headers: dict[str, str] | None = None, extra: dict[str, Any] | list[Any] | None = None) None#

Initialize HTTPException.

Set detail and args if not provided.

Parameters:
  • *args – if detail kwarg not provided, first arg should be error detail.

  • detail – Exception details or message. Will default to args[0] if not provided.

  • status_code – Exception HTTP status code.

  • headers – Headers to set on the response.

  • extra – An extra mapping to attach to the exception.

status_code: int = 500#

Exception status code.

extra: dict[str, Any] | list[Any] | None#

An extra mapping to attach to the exception.

headers: dict[str, str] | None#

Headers to attach to the response.

detail: str#

Exception details or message.

exception litestar.exceptions.ImproperlyConfiguredException#

Bases: HTTPException, ValueError

Application has improper configuration.

exception litestar.exceptions.InternalServerException#

Bases: HTTPException

Server encountered an unexpected condition that prevented it from fulfilling the request.

status_code: int = 500#

Exception status code.

exception litestar.exceptions.InvalidAnnotationException#

Bases: DTOFactoryException

Unexpected DTO type argument.

exception litestar.exceptions.LitestarException#

Bases: Exception

Base exception class from which all Litestar exceptions inherit.

__init__(*args: Any, detail: str = '') None#

Initialize LitestarException.

Parameters:
  • *args – args are converted to str before passing to Exception

  • detail – detail of the exception.

exception litestar.exceptions.LitestarWarning#

Bases: UserWarning

Base class for Litestar warnings

exception litestar.exceptions.MethodNotAllowedException#

Bases: ClientException

Server knows the request method, but the target resource doesn’t support this method.

status_code: int = 405#

Exception status code.

exception litestar.exceptions.MissingDependencyException#

Bases: LitestarException, ImportError

Missing optional dependency.

This exception is raised only when a module depends on a dependency that has not been installed.

__init__(package: str, install_package: str | None = None, extra: str | None = None) None#

Initialize LitestarException.

Parameters:
  • *args – args are converted to str before passing to Exception

  • detail – detail of the exception.

exception litestar.exceptions.NoRouteMatchFoundException#

Bases: InternalServerException

A route with the given name could not be found.

exception litestar.exceptions.NotAuthorizedException#

Bases: ClientException

Request lacks valid authentication credentials for the requested resource.

status_code: int = 401#

Exception status code.

exception litestar.exceptions.NotFoundException#

Bases: ClientException, ValueError

Cannot find the requested resource.

status_code: int = 404#

Exception status code.

exception litestar.exceptions.PermissionDeniedException#

Bases: ClientException

Request understood, but not authorized.

status_code: int = 403#

Exception status code.

exception litestar.exceptions.SerializationException#

Bases: LitestarException

Encoding or decoding of an object failed.

exception litestar.exceptions.ServiceUnavailableException#

Bases: InternalServerException

Server is not ready to handle the request.

status_code: int = 503#

Exception status code.

exception litestar.exceptions.TemplateNotFoundException#

Bases: InternalServerException

Referenced template could not be found.

__init__(*args: Any, template_name: str) None#

Initialize TemplateNotFoundException.

Parameters:
  • *args (Any) – Passed through to super().__init__() - should not include detail.

  • template_name (str) – Name of template that could not be found.

exception litestar.exceptions.TooManyRequestsException#

Bases: ClientException

Request limits have been exceeded.

status_code: int = 429#

Exception status code.

exception litestar.exceptions.ValidationException#

Bases: ClientException, ValueError

Client data validation error.

exception litestar.exceptions.WebSocketDisconnect#

Bases: WebSocketException

Exception class for websocket disconnect events.

__init__(*args: Any, detail: str, code: int = 1000) None#

Initialize WebSocketDisconnect.

Parameters:
  • *args – Any exception args.

  • detail – Exception details.

  • code – Exception code. Should be a number in the >= 1000.

exception litestar.exceptions.WebSocketException#

Bases: LitestarException

Exception class for websocket related events.

__init__(*args: Any, detail: str, code: int = 4500) None#

Initialize WebSocketException.

Parameters:
  • *args – Any exception args.

  • detail – Exception details.

  • code – Exception code. Should be a number in the >= 1000.

code: int#

Exception code. For custom exceptions, this should be a number in the 4000+ range. Other codes can be found in litestar.status_code with the WS_ prefix.