-
Notifications
You must be signed in to change notification settings - Fork 8
Retry access token refresh errors #15
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
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.3.0 | ||
| 2.4.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # encoding: utf-8 | ||
|
|
||
| module BitBucket #:nodoc | ||
| # Raised when BitBucket receives a RefreshToken error | ||
| module Error | ||
| class RefreshToken < BitBucketError | ||
| def initialize(env) | ||
| super(env) | ||
| end | ||
| end | ||
| end # Error | ||
| end # BitBucket |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| require 'faraday' | ||
| require 'bitbucket_rest_api/error' | ||
|
|
||
| REFRESH_TOKEN = %r{Access token expired. Use your refresh token to obtain a new access token.} | ||
|
|
||
| module BitBucket | ||
| class Response::RaiseError < Faraday::Response::Middleware | ||
|
|
||
|
|
@@ -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 commentThe 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?
Author
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. Not that I can think of and unfortunately, I have not been able to reproduce this locally so I am sort of flying blind. |
||
| raise BitBucket::Error::RefreshToken.new(env) | ||
| end | ||
| raise BitBucket::Error::Unauthorized.new(env) | ||
| when 403 | ||
| raise BitBucket::Error::Forbidden.new(env) | ||
|
|
||
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.