Answer the question
In order to leave comments, you need to log in
How to write custom handler for Django REST Framework?
How to actually write your own custom handler? I need to write an api, I first encountered this because I am writing a SPA. The default exception handler is not suitable, it writes in English there, but I need it specifically for my application. I read off the documentation ( click ), but I did not understand anything. Please explain in Russian knowledgeable people.
There is some code:
def custom_exception_handler(exc, context):
response = exception_handler(exc, context)
elif response is not None:
response.data['status_code'] = response.status_code
response.data['error'] = response.data['detail']
del response.data['detail']
return response
Answer the question
In order to leave comments, you need to log in
for example:
if isinstance(exc, PermissionDenied):
# some handling
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question