No project description provided
Project description
DRF Standardized Errors
Standardize your DRF API error responses.
By default, the package will convert all API error responses (4xx and 5xx) to a standardized format:
{
"type": "validation_error",
"errors": [
{
"code": "required",
"message": "This field is required.",
"field": "name"
},
{
"code": "max_length",
"message": "Ensure this value has at most 100 characters.",
"field": "title"
}
]
}
{
"type": "client_error",
"errors": [
{
"code": "authentication_failed",
"message": "Incorrect authentication credentials.",
"field": null
}
]
}
{
"type": "server_error",
"errors": [
{
"code": "error",
"message": "A server error occurred.",
"field": null
}
]
}
Features
- Supports nested serializers and ListSerializer errors
- Plays nicely with error monitoring tools (like Sentry, ...)
Requirements
- python >= 3.8
- Django >= 3.2
- DRF >= 3.12
Quickstart
Install with pip
pip install elefanto-drf-exceptions
Add drf-standardized-errors to your installed apps
INSTALLED_APPS = [
# other apps
"elefanto_drf_exceptions",
]
Register the exception handler
REST_FRAMEWORK = {
# other settings
"EXCEPTION_HANDLER": "elefanto_drf_exceptions.handler.exception_handler"
}
Register the error formatter
DRF_STANDARDIZED_ERRORS = {
"EXCEPTION_FORMATTER_CLASS": "elefanto_drf_exceptions.formatter.ElefantoExceptionFormatter",
}
Notes
Standardized error responses when DEBUG=True
for unhandled exceptions are disabled by default. That is
to allow you to get more information out of the traceback. You can enable standardized errors instead with:
DRF_STANDARDIZED_ERRORS = {
# other settings
"ENABLE_IN_DEBUG_FOR_UNHANDLED_EXCEPTIONS": True
}
Integration with DRF spectacular
If you plan to use drf-spectacular to generate an OpenAPI 3 schema,
install with pip install drf-standardized-errors[openapi]
. After that, check the doc page
for configuring the integration.
Links
This project depends on drf-standardized-errors. For more information go to links below
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for elefanto_drf_exceptions-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4ff8ce01c684ef8e9098b046d0138232764b556b5e6b5ca4d267a145ac0591 |
|
MD5 | 793f48bb4e573e2d1db3a0b97d86d80f |
|
BLAKE2b-256 | 0b0fa0a67836fc667a14181b53f794a30db47cc9d6ef9d3d190fab92d60b330c |
Hashes for elefanto_drf_exceptions-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78ca0324be0e80a6af5cf7ff74319e805d70fb3aa4851c7808b2b1cbff171738 |
|
MD5 | d02ca44c77223bd3cc53ff691477be54 |
|
BLAKE2b-256 | 2338c00bec262be0865ee50b51fe2bd6b762e42b34c26773ac5aef0e0e395211 |