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[原始碼]

初始化 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[原始碼]

初始化 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[原始碼]

初始化 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[原始碼]

初始化 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[原始碼]

初始化 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[原始碼]

初始化 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