Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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(, 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