-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.py
46 lines (36 loc) · 1.37 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class ApiError(Exception):
"""Represents an exception returned by the remote API."""
def __init__(self, status, message=None):
self.status = status
self.message = message
def __str__(self):
if self.message is None:
return str(self.status)
else:
return "%s (%s)" % (self.status, self.message)
class TransportError(Exception):
"""Something went wrong while trying to execute the request."""
def __init__(self, base_exception=None):
self.base_exception = base_exception
def __str__(self):
if self.base_exception:
return str(self.base_exception)
return "An unknown error occurred."
class HTTPError(TransportError):
"""An unexpected HTTP error occurred."""
def __init__(self, status_code):
self.status_code = status_code
def __str__(self):
return "HTTP Error: %d" % self.status_code
class Timeout(Exception):
"""The request timed out."""
pass
class _RetriableRequest(Exception):
"""Signifies that the request can be retried."""
pass
class _OverQueryLimit(ApiError, _RetriableRequest):
"""Signifies that the request failed because the client exceeded its query rate limit.
Normally we treat this as a retriable condition, but we allow the calling code to specify that these requests should
not be retried.
"""
pass