Created
November 22, 2013 14:14
-
-
Save johnnadratowski/7600508 to your computer and use it in GitHub Desktop.
Response Exception - Middleware for Django to return responses using exceptions
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
""" | |
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