Created
October 29, 2013 07:11
-
-
Save chriskief/7210248 to your computer and use it in GitHub Desktop.
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.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