python - Custom exception handler not working as documented in django-rest-framework -
i'm trying write custom exception handler in django-rest-framework, , code same given in example:
from rest_framework.views import exception_handler def custom_exception_handler(exc, context): # call rest framework's default exception handler first, # standard error response. response = exception_handler(exc, context) # add http status code response. if response not none: response.data['status_code'] = response.status_code return response
but on raising exception view, not work, instead throws message:
custom_exception_handler() missing 1 required positional argument: 'context'
i've tried setting first argument none
, so:
def custom_exception_handler(exc, context=none):
but happens:
exception_handler() takes 1 positional argument 2 given
so seems rest_framework.views.exception_handler
takes 1 argument.
indeed case:
def exception_handler(exc): """ returns response should used given exception. default handle rest framework `apiexception`, , django's built-in `validationerror`, `http404` , `permissiondenied` exceptions. unhandled exceptions may return `none`, cause 500 error raised. """
so question is, bug? or missing something, , there way this?..
edit: has been confirmed officially rest_framework team. has been added in latest version seems using v3.0.2 not reflect new documentation.
https://github.com/tomchristie/django-rest-framework/issues/2737
Comments
Post a Comment