|
1 | 1 | class DropboxException(Exception):
|
2 | 2 | """All errors related to making an API request extend this."""
|
3 |
| - pass |
| 3 | + |
| 4 | + def __init__(self, request_id, *args, **kwargs): |
| 5 | + # A request_id can be shared with Dropbox Support to pinpoint the exact |
| 6 | + # request that returns an error. |
| 7 | + super(DropboxException, self).__init__(request_id, *args, **kwargs) |
| 8 | + self.request_id = request_id |
4 | 9 |
|
5 | 10 |
|
6 | 11 | class ApiError(DropboxException):
|
7 | 12 | """Errors produced by the Dropbox API."""
|
8 | 13 |
|
9 |
| - def __init__(self, error, user_message_text, user_message_locale): |
| 14 | + def __init__(self, request_id, error, user_message_text, user_message_locale): |
10 | 15 | """
|
| 16 | + :param (str) request_id: A request_id can be shared with Dropbox |
| 17 | + Support to pinpoint the exact request that returns an error. |
11 | 18 | :param error: An instance of the error data type for the route.
|
12 | 19 | :param (str) user_message_text: A human-readable message that can be
|
13 | 20 | displayed to the end user. Is None, if unavailable.
|
14 | 21 | :param (str) user_message_locale: The locale of ``user_message_text``,
|
15 | 22 | if present.
|
16 | 23 | """
|
17 |
| - super(ApiError, self).__init__(error) |
| 24 | + super(ApiError, self).__init__(request_id, error) |
18 | 25 | self.error = error
|
19 | 26 | self.user_message_text = user_message_text
|
20 | 27 | self.user_message_locale = user_message_locale
|
21 | 28 |
|
22 | 29 | def __repr__(self):
|
23 |
| - return 'ApiError({})'.format(self.error) |
| 30 | + return 'ApiError({!r}, {})'.format(self.request_id, self.error) |
24 | 31 |
|
25 | 32 |
|
26 | 33 | class HttpError(DropboxException):
|
27 | 34 | """Errors produced at the HTTP layer."""
|
28 | 35 |
|
29 |
| - def __init__(self, status_code, body): |
30 |
| - super(HttpError, self).__init__(status_code, body) |
| 36 | + def __init__(self, request_id, status_code, body): |
| 37 | + super(HttpError, self).__init__(request_id, status_code, body) |
31 | 38 | self.status_code = status_code
|
32 | 39 | self.body = body
|
33 | 40 |
|
34 | 41 | def __repr__(self):
|
35 |
| - return 'HttpError({}, {!r})'.format(self.status_code, self.body) |
| 42 | + return 'HttpError({!r}, {}, {!r})'.format( |
| 43 | + self.request_id, self.status_code, self.body) |
36 | 44 |
|
37 | 45 |
|
38 | 46 | class BadInputError(HttpError):
|
39 | 47 | """Errors due to bad input parameters to an API Operation."""
|
40 | 48 |
|
41 |
| - def __init__(self, message): |
42 |
| - super(BadInputError, self).__init__(400, message) |
| 49 | + def __init__(self, request_id, message): |
| 50 | + super(BadInputError, self).__init__(request_id, 400, message) |
43 | 51 | self.message = message
|
44 | 52 |
|
45 | 53 | def __repr__(self):
|
46 |
| - return 'BadInputError({!r})'.format(self.message) |
| 54 | + return 'BadInputError({!r}, {!r})'.format(self.request_id, self.message) |
47 | 55 |
|
48 | 56 |
|
49 | 57 | class AuthError(HttpError):
|
50 | 58 | """Errors due to invalid authentication credentials."""
|
51 | 59 |
|
52 |
| - def __init__(self, error): |
53 |
| - super(AuthError, self).__init__(401, None) |
| 60 | + def __init__(self, request_id, error): |
| 61 | + super(AuthError, self).__init__(request_id, 401, None) |
54 | 62 | self.error = error
|
55 | 63 |
|
56 | 64 | def __repr__(self):
|
57 |
| - return 'AuthError({!r})'.format(self.error) |
| 65 | + return 'AuthError({!r}, {!r})'.format(self.request_id, self.error) |
58 | 66 |
|
59 | 67 |
|
60 | 68 | class RateLimitError(HttpError):
|
61 | 69 | """Error caused by rate limiting."""
|
62 | 70 |
|
63 |
| - def __init__(self, backoff=None): |
64 |
| - super(RateLimitError, self).__init__(429, None) |
| 71 | + def __init__(self, request_id, backoff=None): |
| 72 | + super(RateLimitError, self).__init__(request_id, 429, None) |
65 | 73 | self.backoff = backoff
|
66 | 74 |
|
67 | 75 | def __repr__(self):
|
68 |
| - return 'RateLimitError({!r})'.format(self.backoff) |
| 76 | + return 'RateLimitError({!r}, {!r})'.format(self.request_id, self.backoff) |
69 | 77 |
|
70 | 78 |
|
71 | 79 | class InternalServerError(HttpError):
|
72 | 80 | """Errors due to a problem on Dropbox."""
|
73 | 81 |
|
74 |
| - def __init__(self, status_code, message): |
75 |
| - self.status_code = status_code |
76 |
| - self.message = message |
77 |
| - |
78 | 82 | def __repr__(self):
|
79 |
| - return 'InternalServerError({}, {!r})'.format(self.status_code, self.message) |
| 83 | + return 'InternalServerError({!r}, {}, {!r})'.format( |
| 84 | + self.request_id, self.status_code, self.body) |
0 commit comments