Skip to content

Commit

Permalink
Rescuing InvalidJwtTokenErrors in token exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
zzooeeyy committed Apr 10, 2024
1 parent eeb490b commit fadc394
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/shopify_app/controller_concerns/token_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module ShopifyApp
module TokenExchange
extend ActiveSupport::Concern

INVALID_SESSION_TOKEN_ERRORS = [
ShopifyAPI::Errors::CookieNotFoundError,
ShopifyAPI::Errors::InvalidJwtTokenError,
].freeze

def activate_shopify_session
begin
if current_shopify_session.blank?
Expand All @@ -14,7 +19,7 @@ def activate_shopify_session
@current_shopify_session = nil
retrieve_session_from_token_exchange
end
rescue ShopifyAPI::Errors::CookieNotFoundError
rescue *INVALID_SESSION_TOKEN_ERRORS
return respond_to_invalid_session_token
end

Expand Down Expand Up @@ -76,8 +81,7 @@ def retrieve_session_from_token_exchange

def exchange_token(shop:, session_token:, requested_token_type:)
if session_token.blank?
# respond_to_invalid_session_token
return
raise ShopifyAPI::Errors::InvalidJwtTokenError, "Session token is blank during TokenExchange"
end

begin
Expand All @@ -87,8 +91,8 @@ def exchange_token(shop:, session_token:, requested_token_type:)
requested_token_type: requested_token_type,
)
rescue ShopifyAPI::Errors::InvalidJwtTokenError
# respond_to_invalid_session_token
return
ShopifyApp::Logger.error("Invalid JWT token error occurred during the token exchange")
raise
rescue ShopifyAPI::Errors::HttpResponseError => error
ShopifyApp::Logger.error(
"A #{error.code} error (#{error.class}) occurred during the token exchange. Response: #{error.response.body}",
Expand Down

0 comments on commit fadc394

Please sign in to comment.