@@ -34,7 +34,32 @@ def message(self):
34
34
return self .msg
35
35
36
36
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 ):
38
63
"""Exception class for response objects that cannot be handled."""
39
64
def __init__ (self , message , body ):
40
65
Exception .__init__ (self , message )
@@ -48,12 +73,12 @@ def __str__(self):
48
73
return self .message
49
74
50
75
51
- class BadRequest (GitHubError ):
76
+ class BadRequest (ResponseError ):
52
77
"""Exception class for 400 responses."""
53
78
pass
54
79
55
80
56
- class AuthenticationFailed (GitHubError ):
81
+ class AuthenticationFailed (ResponseError ):
57
82
"""Exception class for 401 responses.
58
83
59
84
Possible reasons:
@@ -64,7 +89,7 @@ class AuthenticationFailed(GitHubError):
64
89
pass
65
90
66
91
67
- class ForbiddenError (GitHubError ):
92
+ class ForbiddenError (ResponseError ):
68
93
"""Exception class for 403 responses.
69
94
70
95
Possible reasons:
@@ -75,32 +100,32 @@ class ForbiddenError(GitHubError):
75
100
pass
76
101
77
102
78
- class NotFoundError (GitHubError ):
103
+ class NotFoundError (ResponseError ):
79
104
"""Exception class for 404 responses."""
80
105
pass
81
106
82
107
83
- class MethodNotAllowed (GitHubError ):
108
+ class MethodNotAllowed (ResponseError ):
84
109
"""Exception class for 405 responses."""
85
110
pass
86
111
87
112
88
- class NotAcceptable (GitHubError ):
113
+ class NotAcceptable (ResponseError ):
89
114
"""Exception class for 406 responses."""
90
115
pass
91
116
92
117
93
- class UnprocessableEntity (GitHubError ):
118
+ class UnprocessableEntity (ResponseError ):
94
119
"""Exception class for 422 responses."""
95
120
pass
96
121
97
122
98
- class ClientError (GitHubError ):
123
+ class ClientError (ResponseError ):
99
124
"""Catch-all for 400 responses that aren't specific errors."""
100
125
pass
101
126
102
127
103
- class ServerError (GitHubError ):
128
+ class ServerError (ResponseError ):
104
129
"""Exception class for 5xx responses."""
105
130
pass
106
131
0 commit comments