diff --git a/lib/stripe/errors.rb b/lib/stripe/errors.rb index c5a5e756..f689ac32 100644 --- a/lib/stripe/errors.rb +++ b/lib/stripe/errors.rb @@ -114,6 +114,12 @@ module Stripe end end + # InvalidClientError is raised when the client doesn't belong to you, or + # the API key mode (live or test) doesn't match the client mode. Or the + # stripe_user_id doesn't exist or isn't connected to your application. + class InvalidClientError < OAuthError + end + # InvalidGrantError is raised when a specified code doesn't exist, is # expired, has been used, or doesn't belong to you; a refresh token doesn't # exist, or doesn't belong to you; or if an API key's mode (live or test) diff --git a/lib/stripe/stripe_client.rb b/lib/stripe/stripe_client.rb index 6df836f3..b8949bf0 100644 --- a/lib/stripe/stripe_client.rb +++ b/lib/stripe/stripe_client.rb @@ -312,6 +312,7 @@ module Stripe }] case error_code + when 'invalid_client' then OAuth::InvalidClientError.new(*args) when 'invalid_grant' then OAuth::InvalidGrantError.new(*args) when 'invalid_request' then OAuth::InvalidRequestError.new(*args) when 'invalid_scope' then OAuth::InvalidScopeError.new(*args) diff --git a/test/stripe/stripe_client_test.rb b/test/stripe/stripe_client_test.rb index 4d9da93b..1caea2d4 100644 --- a/test/stripe/stripe_client_test.rb +++ b/test/stripe/stripe_client_test.rb @@ -368,6 +368,24 @@ module Stripe assert_equal('invalid_grant', e.code) assert_equal('This authorization code has already been used. All tokens issued with this code have been revoked.', e.message) end + + should "raise OAuth::InvalidClientError when error is a string with value 'invalid_client'" do + stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize"). + to_return(body: JSON.generate({ + error: "invalid_client", + error_description: "This application is not connected to stripe account acct_19tLK7DSlTMT26Mk, or that account does not exist.", + }), status: 401) + + client = StripeClient.new + opts = {api_base: Stripe.connect_base} + e = assert_raises Stripe::OAuth::InvalidClientError do + client.execute_request(:post, '/oauth/deauthorize', opts) + end + + assert_equal(401, e.http_status) + 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 end context "idempotency keys" do