Skip to content

exceptions

Definition of extra HTTP exceptions that aren't included in Starlite.

Also, defines functions that translate service and repository exceptions into HTTP exceptions.

ConflictException

Bases: HTTPException

Request conflict with the current state of the target resource.

ForbiddenException

Bases: HTTPException

Server understands the request but refuses to authorize it.

after_exception_hook_handler async

after_exception_hook_handler(exc, _scope, _state)

Binds exc_info key with exception instance as value to structlog context vars.

This must be a coroutine so that it is not wrapped in a thread where we'll lose context.

Parameters:

Name Type Description Default
exc Exception

the exception that was raised.

required
_scope Scope

scope of the request

required
_state State

application state

required

repository_exception_to_http_response

repository_exception_to_http_response(request, exc)

Transform repository exceptions to HTTP exceptions.

Parameters:

Name Type Description Default
request Request[Any, Any]

The request that experienced the exception.

required
exc RepositoryException

Exception raised during handling of the request.

required

Returns:

Type Description
Response[ExceptionResponseContent]

Exception response appropriate to the type of original exception.

service_exception_to_http_response

service_exception_to_http_response(request, exc)

Transform service exceptions to HTTP exceptions.

Parameters:

Name Type Description Default
request Request[Any, Any]

The request that experienced the exception.

required
exc ServiceException

Exception raised during handling of the request.

required

Returns:

Type Description
Response[ExceptionResponseContent]

Exception response appropriate to the type of original exception.