exceptions¶
Here's the reference for all exception classes and handler utilities.
You can import them directly from fastapi_toolsets.exceptions:
from fastapi_toolsets.exceptions import (
ApiException,
UnauthorizedError,
ForbiddenError,
NotFoundError,
ConflictError,
NoSearchableFieldsError,
InvalidFacetFilterError,
InvalidOrderFieldError,
generate_error_responses,
init_exceptions_handlers,
)
fastapi_toolsets.exceptions.exceptions.ApiException
¶
Bases: Exception
Base exception for API errors with structured response.
__init__(detail=None, *, desc=None, data=None)
¶
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str | None
|
Optional human-readable message |
None
|
desc
|
str | None
|
Optional per-instance override for the |
None
|
data
|
Any
|
Optional per-instance override for the |
None
|
fastapi_toolsets.exceptions.exceptions.UnauthorizedError
¶
Bases: ApiException
HTTP 401 - User is not authenticated.
__init__(detail=None, *, desc=None, data=None)
¶
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str | None
|
Optional human-readable message |
None
|
desc
|
str | None
|
Optional per-instance override for the |
None
|
data
|
Any
|
Optional per-instance override for the |
None
|
fastapi_toolsets.exceptions.exceptions.ForbiddenError
¶
Bases: ApiException
HTTP 403 - User lacks required permissions.
__init__(detail=None, *, desc=None, data=None)
¶
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str | None
|
Optional human-readable message |
None
|
desc
|
str | None
|
Optional per-instance override for the |
None
|
data
|
Any
|
Optional per-instance override for the |
None
|
fastapi_toolsets.exceptions.exceptions.NotFoundError
¶
Bases: ApiException
HTTP 404 - Resource not found.
__init__(detail=None, *, desc=None, data=None)
¶
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str | None
|
Optional human-readable message |
None
|
desc
|
str | None
|
Optional per-instance override for the |
None
|
data
|
Any
|
Optional per-instance override for the |
None
|
fastapi_toolsets.exceptions.exceptions.ConflictError
¶
Bases: ApiException
HTTP 409 - Resource conflict.
__init__(detail=None, *, desc=None, data=None)
¶
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detail
|
str | None
|
Optional human-readable message |
None
|
desc
|
str | None
|
Optional per-instance override for the |
None
|
data
|
Any
|
Optional per-instance override for the |
None
|
fastapi_toolsets.exceptions.exceptions.NoSearchableFieldsError
¶
Bases: ApiException
Raised when search is requested but no searchable fields are available.
fastapi_toolsets.exceptions.exceptions.InvalidFacetFilterError
¶
Bases: ApiException
Raised when filter_by contains a key not declared in facet_fields.
fastapi_toolsets.exceptions.exceptions.InvalidOrderFieldError
¶
Bases: ApiException
Raised when order_by contains a field not in the allowed order fields.
fastapi_toolsets.exceptions.exceptions.generate_error_responses(*errors)
¶
fastapi_toolsets.exceptions.handler.init_exceptions_handlers(app)
¶
Register exception handlers and custom OpenAPI schema on a FastAPI app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
FastAPI
|
FastAPI application instance. |
required |
Returns:
| Type | Description |
|---|---|
FastAPI
|
The same FastAPI instance (for chaining). |