Skip to content

Instantly share code, notes, and snippets.

@mertcangokgoz
Created November 12, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mertcangokgoz/aa4e87b5c471a4b9d93593615a0a11e0 to your computer and use it in GitHub Desktop.
Save mertcangokgoz/aa4e87b5c471a4b9d93593615a0a11e0 to your computer and use it in GitHub Desktop.
Django REST Framework custom exeption handler
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