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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55ff18608f622878f7813cb42e047847046f1bef8fa7c1148c2eb2acb31c99cc |
|
MD5 | 1140b187f355a1427472cfc8f8e4eb87 |
|
BLAKE2b-256 | 92b133e90b8dc13726f1c1ebb6e1350cb8593251ac762bbd31a96e7abf5d7077 |
Close
Hashes for drf_standardized_errors-0.10.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55cc4dffcfac0bdf013d61a24ee6125406db192cd92fa263a3681f1ace4cab17 |
|
MD5 | 087307a8be514bf51e9c711d6c56b536 |
|
BLAKE2b-256 | f36015e65aff7ce91d9d2bf68f9a1a1615eda53a8be6bf719147aabdcdfb466c |