Skip to content

Instantly share code, notes, and snippets.

@shichao-an
Created September 10, 2014 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shichao-an/1eb0d3a0fd6f6dff99c8 to your computer and use it in GitHub Desktop.
Save shichao-an/1eb0d3a0fd6f6dff99c8 to your computer and use it in GitHub Desktop.
Custom exception example from requests
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