-
Notifications
You must be signed in to change notification settings - Fork 8
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
Retry access token refresh errors #15
Conversation
@@ -62,7 +62,7 @@ def get(user_name_or_project_key, repo_name, hook_uuid) | |||
_validate_user_repo_params(user, repo) unless user? && repo? | |||
|
|||
get_request( | |||
"/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}" | |||
"/2.0/repositories/#{user_name_or_project_key}/#{repo_name}/hooks/#{hook_uuid}" |
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.
Fixes existing failing test.
lib/bitbucket_rest_api/request.rb
Outdated
yield | ||
rescue BitBucket::Error::RefreshToken | ||
count += 1 | ||
if count < 3 |
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.
I think you want <= 3
here if you want it retry 3 times after the first failed attempt.
@@ -11,6 +13,9 @@ def on_complete(env) | |||
when 400 | |||
raise BitBucket::Error::BadRequest.new(env) | |||
when 401 | |||
if env[:body] =~ REFRESH_TOKEN |
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.
I guess there's no way to determine if its a 'retriable' 401 without using regex to parse the message?
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.
Not that I can think of and unfortunately, I have not been able to reproduce this locally so I am sort of flying blind.
We are still seeing HTTP 401 exceptions containing the body
Access token expired. Use your refresh token to obtain a new access token.
This PR detects these requests and then attempts to retry them 3 times using an incrmental back of of (count * 0.1 seconds). After the 3rd attempt is reached we just throw a
BitBucket::Error::RefreshToken
exception.