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
Metadata
Release files for elefanto-drf-exceptions 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| elefanto_drf_exceptions-0.1.0.tar.gz | 3.2 kB | Without provenance | Details for elefanto_drf_exceptions-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| elefanto_drf_exceptions-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for elefanto_drf_exceptions-0.1.0-py3-none-any.whl |
Total release size: 7.2 kB
Release files / elefanto_drf_exceptions-0.1.0.tar.gz
| Download URL | elefanto_drf_exceptions-0.1.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa4ff8ce01c684ef8e9098b046d0138232764b556b5e6b5ca4d267a145ac0591
|
|
BLAKE2b-256 checksum How to use checksums |
0b0fa0a67836fc667a14181b53f794a30db47cc9d6ef9d3d190fab92d60b330c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-41-generic
|
Release files / elefanto_drf_exceptions-0.1.0-py3-none-any.whl
| Download URL | elefanto_drf_exceptions-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78ca0324be0e80a6af5cf7ff74319e805d70fb3aa4851c7808b2b1cbff171738
|
|
BLAKE2b-256 checksum How to use checksums |
2338c00bec262be0865ee50b51fe2bd6b762e42b34c26773ac5aef0e0e395211
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-41-generic
|
Security for elefanto-drf-exceptions 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.