diff --git a/lib/stripe/stripe_client.rb b/lib/stripe/stripe_client.rb index b8949bf0..213c64c8 100644 --- a/lib/stripe/stripe_client.rb +++ b/lib/stripe/stripe_client.rb @@ -249,8 +249,7 @@ module Stripe if error_data.is_a?(String) error = specific_oauth_error(resp, error_data) - end - if error.nil? + else error = specific_api_error(resp, error_data) end @@ -319,7 +318,9 @@ module Stripe when 'unsupported_grant_type' then OAuth::UnsupportedGrantTypeError.new(*args) when 'unsupported_response_type' then OAuth::UnsupportedResponseTypeError.new(*args) else - nil + # We'd prefer that all errors are typed, but we create a generic + # OAuthError in case we run into a code that we don't recognize. + OAuth::OAuthError.new(*args) end end diff --git a/test/stripe/stripe_client_test.rb b/test/stripe/stripe_client_test.rb index 1caea2d4..46eff5b0 100644 --- a/test/stripe/stripe_client_test.rb +++ b/test/stripe/stripe_client_test.rb @@ -386,6 +386,24 @@ module Stripe assert_equal('invalid_client', e.code) assert_equal('This application is not connected to stripe account acct_19tLK7DSlTMT26Mk, or that account does not exist.', e.message) end + + should "raise Stripe::OAuthError on indeterminate OAuth error" do + stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize"). + to_return(body: JSON.generate({ + error: "new_code_not_recognized", + error_description: "Something.", + }), status: 401) + + client = StripeClient.new + opts = {api_base: Stripe.connect_base} + e = assert_raises Stripe::OAuth::OAuthError do + client.execute_request(:post, '/oauth/deauthorize', opts) + end + + assert_equal(401, e.http_status) + assert_equal("new_code_not_recognized", e.code) + assert_equal("Something.", e.message) + end end context "idempotency keys" do