Skip to content

Commit 2460c6b

Browse files
sigmavirus24omgjlk
authored andcommitted
Add exception to indicate an incomplete data set
This communicates far more clearly to the user what may have happened to cause issues with the response they were expecting. In the case of the issue raised, this points people towards the token they may be using and its scopes. Closes sigmavirus24#693
1 parent 6e5a8b7 commit 2460c6b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

github3/exceptions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ def message(self):
3434
return self.msg
3535

3636

37+
class IncompleteResponse(GitHubError):
38+
"""Exception for a response that doesn't have everything it should."""
39+
40+
def __init__(self, json, exception):
41+
self.response = None
42+
self.code = None
43+
self.json = json
44+
self.errors = []
45+
self.exception = exception
46+
self.msg = (
47+
"The library was expecting more data in the response (%r)."
48+
" Either GitHub modified it's response body, or your token"
49+
" is not properly scoped to retrieve this information."
50+
) % (exception,)
51+
52+
3753
class ResponseError(GitHubError):
3854
"""The base exception for errors stemming from GitHub responses."""
3955
pass

github3/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def __init__(self, json, session=None):
4848
self.last_modified = json.pop('Last-Modified', None)
4949
self._uniq = json.get('url', None)
5050
self._json_data = json
51-
self._update_attributes(json)
51+
try:
52+
self._update_attributes(json)
53+
except KeyError as kerr:
54+
raise exceptions.IncompleteResponse(json, kerr)
5255

5356
def _update_attributes(self, json):
5457
pass

0 commit comments

Comments
 (0)