Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
drf-standardized-errors
Advanced tools
Standardize your DRF API error responses.
By default, the package will convert all API error responses (4xx and 5xx) to the following standardized format:
{
"type": "validation_error",
"errors": [
{
"code": "required",
"detail": "This field is required.",
"attr": "name"
},
{
"code": "max_length",
"detail": "Ensure this value has at most 100 characters.",
"attr": "title"
}
]
}
{
"type": "client_error",
"errors": [
{
"code": "authentication_failed",
"detail": "Incorrect authentication credentials.",
"attr": null
}
]
}
{
"type": "server_error",
"errors": [
{
"code": "error",
"detail": "A server error occurred.",
"attr": null
}
]
}
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.handler.exception_handler"
}
This package is a DRF exception handler, so it standardizes errors that reach a DRF API view. That means it cannot handle errors that happen at the middleware level for example. To handle those as well, you can customize the necessary django error views. You can find more about that in this issue.
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}
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.
This project is MIT licensed.
FAQs
Standardize your API error responses.
We found that drf-standardized-errors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.