Created
September 10, 2014 17:50
-
-
Save shichao-an/1eb0d3a0fd6f6dff99c8 to your computer and use it in GitHub Desktop.
Custom exception example from requests
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
class RequestException(IOError): | |
"""There was an ambiguous exception that occurred while handling your | |
request.""" | |
def __init__(self, *args, **kwargs): | |
""" | |
Initialize RequestException with `request` and `response` objects. | |
""" | |
response = kwargs.pop('response', None) | |
self.response = response | |
self.request = kwargs.pop('request', None) | |
if (response is not None and not self.request and | |
hasattr(response, 'request')): | |
self.request = self.response.request | |
super(RequestException, self).__init__(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment