def specific_oauth_error(resp, error_code, context)
      description = resp.data[:error_description] || error_code

      Util.log_error("Stripe OAuth error",
                     status: resp.http_status,
                     error_code: error_code,
                     error_description: description,
                     idempotency_key: context.idempotency_key,
                     request_id: context.request_id)

      args = [error_code, description, {
        http_status: resp.http_status, http_body: resp.http_body,
        json_body: resp.data, http_headers: resp.http_headers,
      },]

      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)
      when "unsupported_grant_type"    then OAuth::UnsupportedGrantTypeError.new(*args)
      when "unsupported_response_type" then OAuth::UnsupportedResponseTypeError.new(*args)
      else
        # 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
def specific_oauth_error(resp, error_code, context)
      description = resp.data[:error_description] || error_code

      Util.log_error("Stripe OAuth error",
                     status: resp.http_status,
                     error_code: error_code,
                     error_description: description,
                     idempotency_key: context.idempotency_key,
                     request_id: context.request_id)

      args = [error_code, description, {
        http_status: resp.http_status, http_body: resp.http_body,
        json_body: resp.data, http_headers: resp.http_headers,
      },]

      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)
      when "unsupported_grant_type"    then OAuth::UnsupportedGrantTypeError.new(*args)
      when "unsupported_response_type" then OAuth::UnsupportedResponseTypeError.new(*args)
      else
        # 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
Attempts to look at a response's error code and return an OAuth error if
 one matches. Will return `nil` if the code isn't recognized.