Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Created September 13, 2013 14:41
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 andreagrandi/6551622 to your computer and use it in GitHub Desktop.
Save andreagrandi/6551622 to your computer and use it in GitHub Desktop.
Custom Django Rest Framework exception. How to add {"Success": false} to the response.
from rest_framework.views import exception_handler
def custom_exception_handler(exc):
# Call REST framework's default exception handler first,
# to get the standard error response.
response = exception_handler(exc)
# Now add the HTTP status code to the response.
if response is not None:
response.data['Success'] = False
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment