Skip to content

Commit

Permalink
Handle unexpected status errors (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer authored and TheRoyalTnetennba committed Sep 21, 2018
1 parent adc2698 commit c8d3414
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.10.0 (2018-09-21)
* Add UnexpectedStatusError class for http status errors that are not handled.

## 0.9.2 (2018-09-12)
* Update issued_at correctly when it is set simultaneously with expires_in.

Expand Down
5 changes: 5 additions & 0 deletions lib/signet/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class MalformedAuthorizationError < StandardError
class RemoteServerError < StandardError
end

##
# An error indicating that the server sent an unexpected http status
class UnexpectedStatusError < StandardError
end

##
# An error indicating the remote server refused to authorize the client.
class AuthorizationError < StandardError
Expand Down
4 changes: 1 addition & 3 deletions lib/signet/oauth_2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,7 @@ def fetch_access_token(options={})
if body.to_s.strip.length > 0
message += " Server message:\n#{response.body.to_s.strip}"
end
raise ::Signet::AuthorizationError.new(
message, :response => response
)
raise ::Signet::UnexpectedStatusError.new(message)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/signet/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
module Signet
module VERSION
MAJOR = 0
MINOR = 9
TINY = 2
MINOR = 10
TINY = 0
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
Expand Down
4 changes: 2 additions & 2 deletions spec/signet/oauth_2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def build_form_encoded_response(payload)
stubs.verify_stubbed_calls
end

it 'should raise an error if the token server gives an unexpected status' do
it 'should raise an unexpected error if the token server gives an unexpected status' do
@client.client_id = 'client-12345'
@client.client_secret = 'secret-12345'
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
Expand All @@ -604,7 +604,7 @@ def build_form_encoded_response(payload)
@client.fetch_access_token!(
:connection => connection
)
end).to raise_error(Signet::AuthorizationError)
end).to raise_error(Signet::UnexpectedStatusError)
stubs.verify_stubbed_calls
end

Expand Down

0 comments on commit c8d3414

Please sign in to comment.