Skip to content

Instantly share code, notes, and snippets.

@chriskief
Created October 29, 2013 07:11
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 chriskief/7210248 to your computer and use it in GitHub Desktop.
Save chriskief/7210248 to your computer and use it in GitHub Desktop.
from django.utils import timezone
from django.utils.dateformat import format
from django.conf import settings
from app.exceptions.custom import JsonNotFound
from app.lib.shortcuts import render_to_json_response
class ExceptionMiddleware(object):
def process_exception(self, request, exception):
if type(exception) == JsonNotFound:
now = format(timezone.now(), u'U')
kwargs = {}
response = {
'status': '404',
'message': 'Record not found',
'timestamp': now,
'errorcode': settings.API_ERROR_RECORD_NOT_FOUND
}
return render_to_json_response(response, status=404, **kwargs)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment