Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #937 - Adds HTTP method and URL to exceptions. #961

Merged
merged 3 commits into from Jul 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion gcloud/connection.py
Expand Up @@ -415,7 +415,8 @@ def api_request(self, method, path, query_params=None,
target_object=_target_object)

if not 200 <= response.status < 300:
raise make_exception(response, content)
raise make_exception(response, content,
error_info=method + ' ' + url)

string_or_bytes = (six.binary_type, six.text_type)
if content and expect_json and isinstance(content, string_or_bytes):
Expand Down
9 changes: 8 additions & 1 deletion gcloud/exceptions.py
Expand Up @@ -157,7 +157,7 @@ class ServiceUnavailable(ServerError):
code = 503


def make_exception(response, content, use_json=True):
def make_exception(response, content, error_info=None, use_json=True):
"""Factory: create exception based on HTTP response code.

:type response: :class:`httplib2.Response` or other HTTP response object
Expand All @@ -167,6 +167,10 @@ def make_exception(response, content, use_json=True):
:type content: string or dictionary
:param content: The body of the HTTP error response.

:type error_info: string
:param error_info: Optional string giving extra information about the
failed request.

:type use_json: boolean
:param use_json: Flag indicating if ``content`` is expected to be JSON.

Expand All @@ -187,6 +191,9 @@ def make_exception(response, content, use_json=True):
message = payload.get('error', {}).get('message', '')
errors = payload.get('error', {}).get('errors', ())

if error_info is not None:
message += ' (%s)' % (error_info,)

try:
klass = _HTTP_CODE_TO_EXCEPTION[response.status]
except KeyError:
Expand Down