-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exceptions now expose X-Dropbox-Request-Id header.
- Loading branch information
Showing
5 changed files
with
44 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,84 @@ | ||
class DropboxException(Exception): | ||
"""All errors related to making an API request extend this.""" | ||
pass | ||
|
||
def __init__(self, request_id, *args, **kwargs): | ||
# A request_id can be shared with Dropbox Support to pinpoint the exact | ||
# request that returns an error. | ||
super(DropboxException, self).__init__(request_id, *args, **kwargs) | ||
self.request_id = request_id | ||
|
||
|
||
class ApiError(DropboxException): | ||
"""Errors produced by the Dropbox API.""" | ||
|
||
def __init__(self, error, user_message_text, user_message_locale): | ||
def __init__(self, request_id, error, user_message_text, user_message_locale): | ||
""" | ||
:param (str) request_id: A request_id can be shared with Dropbox | ||
Support to pinpoint the exact request that returns an error. | ||
:param error: An instance of the error data type for the route. | ||
:param (str) user_message_text: A human-readable message that can be | ||
displayed to the end user. Is None, if unavailable. | ||
:param (str) user_message_locale: The locale of ``user_message_text``, | ||
if present. | ||
""" | ||
super(ApiError, self).__init__(error) | ||
super(ApiError, self).__init__(request_id, error) | ||
self.error = error | ||
self.user_message_text = user_message_text | ||
self.user_message_locale = user_message_locale | ||
|
||
def __repr__(self): | ||
return 'ApiError({})'.format(self.error) | ||
return 'ApiError({!r}, {})'.format(self.request_id, self.error) | ||
|
||
|
||
class HttpError(DropboxException): | ||
"""Errors produced at the HTTP layer.""" | ||
|
||
def __init__(self, status_code, body): | ||
super(HttpError, self).__init__(status_code, body) | ||
def __init__(self, request_id, status_code, body): | ||
super(HttpError, self).__init__(request_id, status_code, body) | ||
self.status_code = status_code | ||
self.body = body | ||
|
||
def __repr__(self): | ||
return 'HttpError({}, {!r})'.format(self.status_code, self.body) | ||
return 'HttpError({!r}, {}, {!r})'.format( | ||
self.request_id, self.status_code, self.body) | ||
|
||
|
||
class BadInputError(HttpError): | ||
"""Errors due to bad input parameters to an API Operation.""" | ||
|
||
def __init__(self, message): | ||
super(BadInputError, self).__init__(400, message) | ||
def __init__(self, request_id, message): | ||
super(BadInputError, self).__init__(request_id, 400, message) | ||
self.message = message | ||
|
||
def __repr__(self): | ||
return 'BadInputError({!r})'.format(self.message) | ||
return 'BadInputError({!r}, {!r})'.format(self.request_id, self.message) | ||
|
||
|
||
class AuthError(HttpError): | ||
"""Errors due to invalid authentication credentials.""" | ||
|
||
def __init__(self, error): | ||
super(AuthError, self).__init__(401, None) | ||
def __init__(self, request_id, error): | ||
super(AuthError, self).__init__(request_id, 401, None) | ||
self.error = error | ||
|
||
def __repr__(self): | ||
return 'AuthError({!r})'.format(self.error) | ||
return 'AuthError({!r}, {!r})'.format(self.request_id, self.error) | ||
|
||
|
||
class RateLimitError(HttpError): | ||
"""Error caused by rate limiting.""" | ||
|
||
def __init__(self, backoff=None): | ||
super(RateLimitError, self).__init__(429, None) | ||
def __init__(self, request_id, backoff=None): | ||
super(RateLimitError, self).__init__(request_id, 429, None) | ||
self.backoff = backoff | ||
|
||
def __repr__(self): | ||
return 'RateLimitError({!r})'.format(self.backoff) | ||
return 'RateLimitError({!r}, {!r})'.format(self.request_id, self.backoff) | ||
|
||
|
||
class InternalServerError(HttpError): | ||
"""Errors due to a problem on Dropbox.""" | ||
|
||
def __init__(self, status_code, message): | ||
self.status_code = status_code | ||
self.message = message | ||
|
||
def __repr__(self): | ||
return 'InternalServerError({}, {!r})'.format(self.status_code, self.message) | ||
return 'InternalServerError({!r}, {}, {!r})'.format( | ||
self.request_id, self.status_code, self.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
|
||
dist = setup( | ||
name='dropbox', | ||
version='4.0', | ||
version='4.0.1', | ||
description='Official Dropbox API Client', | ||
author='Dropbox', | ||
author_email='[email protected]', | ||
|