From c8d34146da89bc9539ae70589a283baa79828056 Mon Sep 17 00:00:00 2001 From: Yoann Lecuyer Date: Fri, 21 Sep 2018 18:14:55 +0200 Subject: [PATCH] Handle unexpected status errors (#101) --- CHANGELOG.md | 3 +++ lib/signet/errors.rb | 5 +++++ lib/signet/oauth_2/client.rb | 4 +--- lib/signet/version.rb | 4 ++-- spec/signet/oauth_2/client_spec.rb | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0ba214..5a0b367 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/signet/errors.rb b/lib/signet/errors.rb index c40d52e..45a5791 100644 --- a/lib/signet/errors.rb +++ b/lib/signet/errors.rb @@ -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 diff --git a/lib/signet/oauth_2/client.rb b/lib/signet/oauth_2/client.rb index 77130e4..7256429 100644 --- a/lib/signet/oauth_2/client.rb +++ b/lib/signet/oauth_2/client.rb @@ -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 diff --git a/lib/signet/version.rb b/lib/signet/version.rb index 67a0f05..1a00446 100644 --- a/lib/signet/version.rb +++ b/lib/signet/version.rb @@ -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('.') diff --git a/spec/signet/oauth_2/client_spec.rb b/spec/signet/oauth_2/client_spec.rb index 7b35aaf..50a5e51 100644 --- a/spec/signet/oauth_2/client_spec.rb +++ b/spec/signet/oauth_2/client_spec.rb @@ -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| @@ -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