Skip to content

Commit

Permalink
fix 'internal_failure' condition
Browse files Browse the repository at this point in the history
  • Loading branch information
georgysavva committed Nov 13, 2019
1 parent e61a873 commit 55ee597
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 7 additions & 4 deletions google/oauth2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,21 @@ def _token_endpoint_request(request, token_uri, body):
while True:
response = request(method="POST", url=token_uri, headers=headers, body=body)
response_body = response.data.decode("utf-8")
response_data = json.loads(response_body)

if response.status == http_client.OK:
break
else:
error_desc = json.loads(response_body).get("error_description") or ""
if error_desc == "internal_failure" and retry < 1:
error_desc = response_data.get("error_description") or ""
error_code = response_data.get("error") or ""
if (
any(e == "internal_failure" for e in (error_code, error_desc))
and retry < 1
):
retry += 1
continue
_handle_error_response(response_body)

response_data = json.loads(response_body)

return response_data


Expand Down
9 changes: 9 additions & 0 deletions tests/oauth2/test__client.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ def test__token_endpoint_request_internal_failure_error():
{"error": "internal_failure", "error_description": "internal_failure"},
)

request = make_request(
{"error": "internal_failure"}, status=http_client.BAD_REQUEST
)

with pytest.raises(exceptions.RefreshError):
_client._token_endpoint_request(
request, "http://example.com", {"error": "internal_failure"}
)


def verify_request_params(request, params):
request_body = request.call_args[1]["body"]
Expand Down

0 comments on commit 55ee597

Please sign in to comment.