Created
September 13, 2013 14:41
-
-
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.
This file contains hidden or 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 | |
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