Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gcloud/connection.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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