-
Notifications
You must be signed in to change notification settings - Fork 54
[Issue #9021] Add retries if Login.gov fails when we ask for token details #9023
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -161,15 +161,26 @@ def handle_login_gov_token( | |||||||||||||||||||||||||
| # call the token endpoint (make a client) | ||||||||||||||||||||||||||
| # https://developers.login.gov/oidc/token/ | ||||||||||||||||||||||||||
| client = get_login_gov_client() | ||||||||||||||||||||||||||
| response = client.get_token( | ||||||||||||||||||||||||||
| OauthTokenRequest( | ||||||||||||||||||||||||||
| code=login_gov_data.code, client_assertion=get_login_gov_client_assertion() | ||||||||||||||||||||||||||
| limit = 3 | ||||||||||||||||||||||||||
| tries = 0 | ||||||||||||||||||||||||||
| while tries < limit: | ||||||||||||||||||||||||||
| tries += 1 | ||||||||||||||||||||||||||
| response = client.get_token( | ||||||||||||||||||||||||||
| OauthTokenRequest( | ||||||||||||||||||||||||||
| code=login_gov_data.code, client_assertion=get_login_gov_client_assertion() | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # If this request failed, we'll assume we're the issue and 500 | ||||||||||||||||||||||||||
| if response.is_error_response(): | ||||||||||||||||||||||||||
| raise_flask_error(500, response.error_description) | ||||||||||||||||||||||||||
| # If this request failed, we'll assume we're the issue and 500 | ||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should update this as with the retries it isn't quite right? |
||||||||||||||||||||||||||
| if response.is_error_response(): | ||||||||||||||||||||||||||
| if tries == limit: | ||||||||||||||||||||||||||
| raise_flask_error(500, response.error_description) | ||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||
| logger.info( | ||||||||||||||||||||||||||
| "Retrying call to Login.gov after receiving error", | ||||||||||||||||||||||||||
| extra={"tries": tries, "limit": limit}, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
|
Comment on lines
+178
to
+183
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant to do this - as written it would always call 3 times as the loop never breaks before 3 tries.
Suggested change
Alternatively, if we wanted to use tenacity, seems they have a |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Process the token response from login.gov | ||||||||||||||||||||||||||
| # which will create/update a user in the DB | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than setting the retries by using the dict directly, what if we add a param to the add token function to do it?
Then that simplifies the logic below a bit as it'll always be set.