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/releases
- 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
File details
Details for the file drf-standardized-errors-0.10.2.tar.gz
.
File metadata
- Download URL: drf-standardized-errors-0.10.2.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.27.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ccc46d78455b1438c40d01567e5c47b8c141b61bde37dc8d62ecf5bf4e87b3ee
|
|
MD5 |
eca2afe25dfbe6852c66f30728487c7e
|
|
BLAKE2b-256 |
7840b0ee3a4cc1718a9f774ceba1f7ff34c1514a3a52ea3b0b6c4f30a79f71d3
|
File details
Details for the file drf_standardized_errors-0.10.2-py3-none-any.whl
.
File metadata
- Download URL: drf_standardized_errors-0.10.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.27.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a693c8e1eefbc040395839c555f645591f1f75c717ea0b87c4ccc1a4a6552f51
|
|
MD5 |
88054892978d35ac231b773ff91dea87
|
|
BLAKE2b-256 |
8d4d5a00956c7916c7aff55bbf322b24377adaadfc8c18ed0adb05109e227e29
|