Standardized and easy-to-parse API error responses for DRF.
Low maintenance activity. Last release over 3 years ago, commits in 1 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install drf-exceptions-hog
DRF Exceptions Hog
Standardized and easy-to-parse API error responses for Django REST Framework.
After reusing similar code in multiple projects, we realized this might actually help others. The problem we're trying to solve is that DRF exceptions tend to vary in format and therefore require complex parsing logic on the frontend, which generally needs to be implemented in more than one language or framework. This simple package standardizes the exception responses to simplify the parsing logic on the frontend and enable developers to provide clear errors to their users (instead of the cryptic or even shady-looking parsing errors). This package is inspired on the way Stripe API handles errors. See an example below.
You will get predictable responses like these:
// Example 1
{
"type": "validation_error",
"code": "required",
"detail": "This field is required.",
"attr": "name"
}
// Example 2
{
"type": "authentication_error",
"code": "permission_denied",
"detail": "You do not have permission to perform this operation.",
"attr": null
}
instead of these:
// Example 1
{
"name": ["This field is required."]
}
// Example 2
{
"detail": "You do not have permission to perform this operation."
}
Note: Currently we only support JSON responses. If you'd like us to support a different response format, please open an issue or a PR (see Contributing)
🔌 Usage
To start using DRF Exceptions Hog please follow these instructions:
Install the package with pip
pip install drf-exceptions-hog
Update your DRF configuration on your .