Skip to content

Instantly share code, notes, and snippets.

@satran
Created July 16, 2012 07:22

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 16, 2012.
    15 changes: 15 additions & 0 deletions json_exception.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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')