
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Never liked DRF plain old errors? Forget that and accept RFC 7807 - Problem Details!
This library implements RFC 7807 in our favorite Django REST Framework! Or, in layman terms, it introduces "Problem Details" in the HTTP APIs.
Install the library as you would for any django library.
pip install drf-problems
INSTALLED_APPS = (
...
'drf_problems',
)
settings.py
, update:REST_FRAMEWORK = {
...
'EXCEPTION_HANDLER': 'drf_problems.exceptions.exception_handler',
urls.py
:urlpatterns = [
...
path('', include('drf_problems.urls'))
]
In your exception class, define default_code
with the error code string which is used in the type URI.
To set custom title, define title
with the human-readable summary of the problem type.
To set description, define description
with a long paragraph describing the problem.
Finally, make sure to register your exception with drf_problems.utils.register_exception
function or drf_problems.utils.register
decorator.
Here's a sample exception class:
from drf_problems.utils import register_exception, register
@register # Either use this decorator
class InvalidVersionRequestedException(exceptions.NotAcceptable):
default_code = 'invalid_version'
title = 'Invalid API version'
default_detail = 'Provided API version is invalid.')
description = 'Malformed or unsupported version string is provided with the request.'
register_exception(InvalidVersionRequestedException) # Or this method directly.
Use either drf_problems.permissions.ProblemPermissionMixin
mixin class with your existing permissions, or extend directly from drf_problems.permissions.BaseProblemPermission
.
Define exception_class
in the permissions to the desired exception class.
For flexibility, you can even set exception instance by setting exception
attribute on the permission object.
Here's a sample permissions class:
from drf_problems.permissions import BaseProblemPermission
class MinimumVersionRequiredPermission(BaseProblemPermission):
exception_class = InvalidVersionRequestedException
Note: The permissions wouldn't throw the desired exception from the view, until the view is extended from the drf_problems.mixins.AllowPermissionWithExceptionViewMixin
mixin. So, remember to update your views too, for which permissions are updated!
Contributions are very welcome, of any kind - whether finding new issues or any ideas for enhancements or a pull request.
FAQs
Never liked DRF plain old errors? Forget that and accept RFC 7807 - Problem Details!
We found that drf-problems 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.