8000 Update exception hierarchy · goodwillcoding/github3.py@94c1530 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94c1530

Browse files
committed
Update exception hierarchy
Add exceptions for Requests-raised exceptions. Related-to: sigmavirus24gh-597
1 parent 6e30d06 commit 94c1530

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

github3/exceptions.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,32 @@ def message(self):
3434
return self.msg
3535

3636

37-
class UnprocessableResponseBody(GitHubError):
37+
class ResponseError(GitHubError):
38+
"""The base exception for errors stemming from GitHub responses."""
39+
pass
40+
41+
42+
class TransportError(GitHubError):
43+
"""Catch-all exception for errors coming from Requests."""
44+
45+
msg_format = 'An error occurred while making a request to GitHub: {0}'
46+
47+
def __init__(self, exception):
48+
Exception.__init__(self, exception)
49+
self.exception = exception
50+
self.msg = self.msg_format.format(str(exception))
51+
52+
def __str__(self):
53+
return '{0}: {1}'.format(type(self.exception), self.msg)
54+
55+
56+
class ConnectionError(TransportError):
57+
"""Exception for errors in connecting to or reading data from GitHub."""
58+
59+
msg_format = 'A connection-level exception occurred: {0}'
60+
61+
62+
class UnprocessableResponseBody(ResponseError):
3863
"""Exception class for response objects that cannot be handled."""
3964
def __init__(self, message, body):
4065
Exception.__init__(self, message)
@@ -48,12 +73,12 @@ def __str__(self):
4873
return self.message
4974

5075

51-
class BadRequest(GitHubError):
76+
class BadRequest(ResponseError):
5277
"""Exception class for 400 responses."""
5378
pass
5479

5580

56-
class AuthenticationFailed(GitHubError):
81+
class AuthenticationFailed(ResponseError):
5782
"""Exception class for 401 responses.
5883
5984
Possible reasons:
@@ -64,7 +89,7 @@ class AuthenticationFailed(GitHubError):
6489
pass
6590

6691

67-
class ForbiddenError(GitHubError):
92+
class ForbiddenError(ResponseError):
6893
"""Exception class for 403 responses.
6994
7095
Possible reasons:
@@ -75,32 +100,32 @@ class ForbiddenError(GitHubError):
75100
pass
76101

77102

78-
class NotFoundError(GitHubError):
103+
class NotFoundError(ResponseError):
79104
"""Exception class for 404 responses."""
80105
pass
81106

82107

83-
class MethodNotAllowed(GitHubError):
108+
class MethodNotAllowed(ResponseError):
84109
"""Exception class for 405 responses."""
85110
pass
86111

87112

88-
class NotAcceptable(GitHubError):
113+
class NotAcceptable(ResponseError):
89114
"""Exception class for 406 responses."""
90115
pass
91116

92117

93-
class UnprocessableEntity(GitHubError):
118+
class UnprocessableEntity(ResponseError):
94119
"""Exception class for 422 responses."""
95120
pass
96121

97122

98-
class ClientError(GitHubError):
123+
class ClientError(ResponseError):
99124
"""Catch-all for 400 responses that aren't specific errors."""
100125
pass
101126

102127

103-
class ServerError(GitHubError):
128+
class ServerError(ResponseError):
104129
"""Exception class for 5xx responses."""
105130
pass
106131

0 commit comments

Comments
 (0)
0