Standardize your API error responses.
Project description
DRF Standardized Errors
Standardize your DRF API error responses.
By default, the API error responses (4xx and 5xx) will look like:
{
"type": "validation_error",
"errors": [
{
"code": "required",
"detail": "This field is required.",
"attr": "name"
}
]
}
Features
- Highly customizable: gives you flexibility to define your own standardized error responses and override specific aspects the exception handling process without having to rewrite everything.
- 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 drf-standardized-errors
Add drf-standardized-errors to your installed apps
INSTALLED_APPS = [
# other apps
"drf_standardized_errors",
]
Register the exception handler
REST_FRAMEWORK = {
# other settings
"EXCEPTION_HANDLER": "drf_standardized_errors.exception_handler"
}
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 = {"ENABLE_IN_DEBUG_FOR_UNHANDLED_EXCEPTIONS": True}
Links
- Documentation: https://drf-standardized-errors.readthedocs.io/en/latest/
- Changelog: https://github.com/ghazi-git/drf-standardized-errors/blob/main/docs/changelog.md
- Code & issues: https://github.com/ghazi-git/drf-standardized-errors
- PyPI: https://pypi.org/project/drf-standardized-errors/
Licence
This project is MIT licensed.
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
Close
Hashes for drf-standardized-errors-0.10.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 848a2128a8d6f0aadb97fa27894a87727b73b03fe63f43d836f2a498f41227c1 |
|
MD5 | e23235b899fa0eee31cf48f683364491 |
|
BLAKE2b-256 | b522134842adcff6d0e3a6235d18619db19777d69c87e86ee94987c828adead7 |
Close
Hashes for drf_standardized_errors-0.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e368c0c9dcd942ba533fdd02810a3b681c64d25be983ec49035bd37beb665a2 |
|
MD5 | 54edafc58dd1a51f910ce2b0c54c01ee |
|
BLAKE2b-256 | 9173fb8c6ab9178012f7ed92022df41fe3a9ca7efce75e1f47eeaa57a7425f39 |