exceptions

exception litestar.exceptions.ClientException[源代码]

基类:HTTPException

Client error.

status_code: int = 400

Exception status code.

exception litestar.exceptions.DTOFactoryException[源代码]

基类:LitestarException

Base DTO exception type.

exception litestar.exceptions.HTTPException[源代码]

基类: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 | Literal[_EmptyEnum.EMPTY] = _EmptyEnum.EMPTY, extra: dict[str, Any] | list[Any] | None | Literal[_EmptyEnum.EMPTY] = _EmptyEnum.EMPTY) None[源代码]

Initialize HTTPException.

Set detail and args if not provided.

参数:
  • *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. Defaults to the class's headers if not provided. Set to None explicitly to unset the default.

  • extra -- An extra mapping to attach to the exception. Defaults to the class's extra if not provided. Set to None explicitly to unset the default.

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

An extra mapping to attach to the exception.

headers: dict[str, str] | None = None

Headers to attach to the response.

status_code: int = 500

Exception status code.

detail: str

Exception details or message.

exception litestar.exceptions.ImproperlyConfiguredException[源代码]

基类:HTTPException, ValueError

Application has improper configuration.

exception litestar.exceptions.InternalServerException[源代码]

基类:HTTPException

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

status_code: int = 500

Exception status code.

exception litestar.exceptions.InvalidAnnotationException[源代码]

基类:DTOFactoryException

Unexpected DTO type argument.

exception litestar.exceptions.LitestarException[源代码]

基类:Exception

Base exception class from which all Litestar exceptions inherit.

__init__(*args: Any, detail: str = '') None[源代码]

Initialize LitestarException.

参数:
  • *args -- args are converted to str before passing to Exception

  • detail -- detail of the exception.

exception litestar.exceptions.LitestarWarning[源代码]

基类:UserWarning

Base class for Litestar warnings

exception litestar.exceptions.MethodNotAllowedException[源代码]

基类: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[源代码]

基类: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.

参数:
  • *args -- args are converted to str before passing to Exception

  • detail -- detail of the exception.

exception litestar.exceptions.NoRouteMatchFoundException[源代码]

基类:InternalServerException

A route with the given name could not be found.

exception litestar.exceptions.NotAuthorizedException[源代码]

基类:ClientException

Request lacks valid authentication credentials for the requested resource.

status_code: int = 401

Exception status code.

exception litestar.exceptions.NotFoundException[源代码]

基类:ClientException, ValueError

Cannot find the requested resource.

status_code: int = 404

Exception status code.

exception litestar.exceptions.PermissionDeniedException[源代码]

基类:ClientException

Request understood, but not authorized.

status_code: int = 403

Exception status code.

exception litestar.exceptions.SerializationException[源代码]

基类:LitestarException

Encoding or decoding of an object failed.

exception litestar.exceptions.ServiceUnavailableException[源代码]

基类:InternalServerException

Server is not ready to handle the request.

status_code: int = 503

Exception status code.

exception litestar.exceptions.TemplateNotFoundException[源代码]

基类:InternalServerException

Referenced template could not be found.

__init__(*args: Any, template_name: str) None[源代码]

Initialize TemplateNotFoundException.

参数:
  • *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[源代码]

基类:ClientException

Request limits have been exceeded.

status_code: int = 429

Exception status code.

exception litestar.exceptions.ValidationException[源代码]

基类:ClientException, ValueError

Client data validation error.

exception litestar.exceptions.WebSocketDisconnect[源代码]

基类:WebSocketException

Exception class for websocket disconnect events.

__init__(*args: Any, detail: str, code: int = 1000) None[源代码]

Initialize WebSocketDisconnect.

参数:
  • *args -- Any exception args.

  • detail -- Exception details.

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

exception litestar.exceptions.WebSocketException[源代码]

基类:LitestarException

Exception class for websocket related events.

__init__(*args: Any, detail: str, code: int = 4500) None[源代码]

Initialize WebSocketException.

参数:
  • *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.

class litestar.exceptions.responses.ExceptionResponseContent[源代码]

基类:object

Represent the contents of an exception-response.

status_code: int

Exception status code.

detail: str

Exception details or message.

media_type: MediaType | str

Media type of the response.

headers: dict[str, str] | None = None

Headers to attach to the response.

__init__(status_code: int, detail: str, media_type: MediaType | str, headers: dict[str, str] | None = None, extra: dict[str, Any] | list[Any] | None = None) None
extra: dict[str, Any] | list[Any] | None = None

An extra mapping to attach to the exception.

to_response(request: Request | None = None) Response[源代码]

Create a response from the model attributes.

返回:

A response instance.

litestar.exceptions.responses.create_debug_response(request: Request, exc: Exception) Response[源代码]

Create a debug response from an exception.

参数:
  • request -- The request that triggered the exception.

  • exc -- An exception.

返回:

Debug response constructed from exception details.

返回类型:

Response

litestar.exceptions.responses.create_exception_response(request: Request[Any, Any, Any], exc: Exception) Response[源代码]

Construct a response from an exception.

备注

  • For instances of HTTPException or other exception classes that have a status_code attribute (e.g. Starlette exceptions), the status code is drawn from the exception, otherwise response status is HTTP_500_INTERNAL_SERVER_ERROR.

参数:
  • request -- The request that triggered the exception.

  • exc -- An exception.

返回:

HTTP response constructed from exception details.

返回类型:

Response