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

feat: Adds support for errors.py to also use 'errors' for error_details #1281

Merged
merged 3 commits into from Apr 3, 2021
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
2 changes: 1 addition & 1 deletion googleapiclient/errors.py
Expand Up @@ -61,7 +61,7 @@ def _get_reason(self):
data = self.content.decode("utf-8")
if isinstance(data, dict):
reason = data["error"]["message"]
error_detail_keyword = next((kw for kw in ["detail", "details", "message"] if kw in data["error"]), "")
error_detail_keyword = next((kw for kw in ["detail", "details", "errors", "message"] if kw in data["error"]), "")
if error_detail_keyword:
self.error_details = data["error"][error_detail_keyword]
elif isinstance(data, list) and len(data) > 0:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_errors.py
Expand Up @@ -141,5 +141,6 @@ def test_error_detail_for_missing_message_in_error(self):
reason="Failed",
)
error = HttpError(resp, content)
self.assertEqual(str(error), '<HttpError 400 when requesting None returned "country is required". Details: "country is required">')
self.assertEqual(error.error_details, 'country is required')
expected_error_details = "[{'domain': 'global', 'reason': 'required', 'message': 'country is required', 'locationType': 'parameter', 'location': 'country'}]"
self.assertEqual(str(error), '<HttpError 400 when requesting None returned "country is required". Details: "%s">' % expected_error_details)
self.assertEqual(str(error.error_details), expected_error_details)
2 changes: 1 addition & 1 deletion tests/test_http.py
Expand Up @@ -1587,7 +1587,7 @@ def test_execute_batch_http_error(self):
"<HttpError 403 when requesting "
"https://www.googleapis.com/someapi/v1/collection/?foo=bar returned "
'"Access Not Configured". '
'Details: "Access Not Configured">'
"Details: \"[{'domain': 'usageLimits', 'reason': 'accessNotConfigured', 'message': 'Access Not Configured', 'debugInfo': 'QuotaState: BLOCKED'}]\">"
)
self.assertEqual(expected, str(callbacks.exceptions["2"]))

Expand Down