Created
July 16, 2012 07:22
-
-
Save satran/3121331 to your computer and use it in GitHub Desktop.
JSON exception Middleware
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 django.http import HttpResponseServerError | |
import json | |
import traceback | |
import sys | |
class JSONException(object): | |
''' | |
Return all exceptions as a JSON object. | |
''' | |
def process_exception(self, request, exception): | |
exc_traceback = sys.exc_info()[-1] | |
response = {"error": str(exception)} | |
response['details'] = traceback.extract_tb(exc_traceback) | |
return HttpResponseServerError(json.dumps(response), content_type='application/json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment