diff --git a/googleapiclient/errors.py b/googleapiclient/errors.py index 33ee682a4d0..332327ec04f 100644 --- a/googleapiclient/errors.py +++ b/googleapiclient/errors.py @@ -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: diff --git a/tests/test_errors.py b/tests/test_errors.py index 9c139a6b60e..955526ff307 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -141,5 +141,6 @@ def test_error_detail_for_missing_message_in_error(self): reason="Failed", ) error = HttpError(resp, content) - self.assertEqual(str(error), '') - 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), '' % expected_error_details) + self.assertEqual(str(error.error_details), expected_error_details) diff --git a/tests/test_http.py b/tests/test_http.py index 4e613589499..bfd9ba865d7 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -1587,7 +1587,7 @@ def test_execute_batch_http_error(self): "' + "Details: \"[{'domain': 'usageLimits', 'reason': 'accessNotConfigured', 'message': 'Access Not Configured', 'debugInfo': 'QuotaState: BLOCKED'}]\">" ) self.assertEqual(expected, str(callbacks.exceptions["2"]))