Skip to content

Instantly share code, notes, and snippets.

@johnnadratowski
Created November 22, 2013 14:14
Show Gist options
  • Save johnnadratowski/7600508 to your computer and use it in GitHub Desktop.
Save johnnadratowski/7600508 to your computer and use it in GitHub Desktop.
Response Exception - Middleware for Django to return responses using exceptions
"""
Contains the middleware class implementation for the ResponseException
"""
class ResponseException(Exception):
def __init__(self, response):
super(Exception, self).__init__()
self.response = response
class ResponseExceptionMiddleware(object):
def process_exception(self, request, exception):
if isinstance(exception, ResponseException):
return exception.response
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment