Created
November 12, 2020 08:59
-
-
Save mertcangokgoz/aa4e87b5c471a4b9d93593615a0a11e0 to your computer and use it in GitHub Desktop.
Django REST Framework custom exeption handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.views import exception_handler | |
from rest_framework.response import Response | |
def JsonAPICustomExeptionHandler(exc, context): | |
response = exception_handler(exc, context) | |
if response is not None: | |
return Response({ | |
"errors": { | |
"status_code": response.status_code, | |
"detail": response.data.get('detail') | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment