Skip to content

Commit a5d2081

Browse files
authored
feat: Adds support for errors.py to also use 'errors' for error_details (#1281)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/google-api-python-client/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes #1279 🦕
1 parent cc717a1 commit a5d2081

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

googleapiclient/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_reason(self):
6161
data = self.content.decode("utf-8")
6262
if isinstance(data, dict):
6363
reason = data["error"]["message"]
64-
error_detail_keyword = next((kw for kw in ["detail", "details", "message"] if kw in data["error"]), "")
64+
error_detail_keyword = next((kw for kw in ["detail", "details", "errors", "message"] if kw in data["error"]), "")
6565
if error_detail_keyword:
6666
self.error_details = data["error"][error_detail_keyword]
6767
elif isinstance(data, list) and len(data) > 0:

tests/test_errors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,6 @@ def test_error_detail_for_missing_message_in_error(self):
141141
reason="Failed",
142142
)
143143
error = HttpError(resp, content)
144-
self.assertEqual(str(error), '<HttpError 400 when requesting None returned "country is required". Details: "country is required">')
145-
self.assertEqual(error.error_details, 'country is required')
144+
expected_error_details = "[{'domain': 'global', 'reason': 'required', 'message': 'country is required', 'locationType': 'parameter', 'location': 'country'}]"
145+
self.assertEqual(str(error), '<HttpError 400 when requesting None returned "country is required". Details: "%s">' % expected_error_details)
146+
self.assertEqual(str(error.error_details), expected_error_details)

tests/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ def test_execute_batch_http_error(self):
15871587
"<HttpError 403 when requesting "
15881588
"https://www.googleapis.com/someapi/v1/collection/?foo=bar returned "
15891589
'"Access Not Configured". '
1590-
'Details: "Access Not Configured">'
1590+
"Details: \"[{'domain': 'usageLimits', 'reason': 'accessNotConfigured', 'message': 'Access Not Configured', 'debugInfo': 'QuotaState: BLOCKED'}]\">"
15911591
)
15921592
self.assertEqual(expected, str(callbacks.exceptions["2"]))
15931593

0 commit comments

Comments
 (0)