diff options
author | 2012-02-05 12:25:51 +0100 | |
---|---|---|
committer | 2012-02-05 12:25:51 +0100 | |
commit | b44952ee781208ddcc5eec67a7b1ba58e2f44c1c (patch) | |
tree | f2fcaf642a3cbd37911334f864d825a8215e3e97 /pygithub3/core/errors.py | |
parent | Renaming (What I was thinking?) (diff) | |
download | python-github3-b44952ee781208ddcc5eec67a7b1ba58e2f44c1c.tar.xz python-github3-b44952ee781208ddcc5eec67a7b1ba58e2f44c1c.zip |
Added asserts to "that never happens"
Also fix response raises
Diffstat (limited to 'pygithub3/core/errors.py')
-rw-r--r-- | pygithub3/core/errors.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/pygithub3/core/errors.py b/pygithub3/core/errors.py index 0d58c16..1a9ed0c 100644 --- a/pygithub3/core/errors.py +++ b/pygithub3/core/errors.py @@ -12,6 +12,10 @@ class UnprocessableEntity(Exception): pass +class NotFound(Exception): + pass + + class GithubError(object): """ Handler for API errors """ @@ -23,15 +27,18 @@ class GithubError(object): except (ValueError, TypeError): self.debug = {'message': response.content} + def error_404(self): + raise NotFound("404 - %s" % self.debug.get('message')) + def error_400(self): - return BadRequest("400 - %s" % self.debug.get('message')) + raise BadRequest("400 - %s" % self.debug.get('message')) def error_422(self): errors = self.debug.get('errors') - if errors: - errors = ['{resource}: {code} => {field}'.format(**error) - for error in errors] - return UnprocessableEntity( + errors = ['Resource: {resource}: {field} => {message} ({code})'.format( + **error) + for error in errors] + raise UnprocessableEntity( '422 - %s %s' % (self.debug.get('message'), errors)) def process(self): |