Skip to content

Commit

Permalink
Don't delete shop session on 401 error
Browse files Browse the repository at this point in the history
  • Loading branch information
zzooeeyy committed May 6, 2024
1 parent 1eacea7 commit 6736026
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/shopify_app/admin_api/with_token_refetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def with_token_refetch(session, shopify_id_token)
ShopifyApp::Logger.debug("Encountered error: #{error.code} - #{error.response.inspect}, re-raising")
elsif retrying
ShopifyApp::Logger.debug("Shopify API returned a 401 Unauthorized error that was not corrected " \
"with token exchange, deleting current session and re-raising")
ShopifyApp::SessionRepository.delete_session(session.id)
"with token exchange, re-raising error")
else
retrying = true
ShopifyApp::Logger.debug("Shopify API returned a 401 Unauthorized error, exchanging token and " \
Expand Down
5 changes: 2 additions & 3 deletions test/shopify_app/admin_api/with_token_refetch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup
assert_equal @new_session.expires, @session.expires
end

test "#with_token_refetch deletes existing token and re-raises when 401 persists" do
test "#with_token_refetch re-raises when 401 persists" do
response = ShopifyAPI::Clients::HttpResponse.new(code: 401, body: "401 message", headers: {})
api_error = ShopifyAPI::Errors::HttpResponseError.new(response: response)

Expand All @@ -67,8 +67,7 @@ def setup
"and retrying with new session")

ShopifyApp::Logger.expects(:debug).with("Shopify API returned a 401 Unauthorized error that was not corrected " \
"with token exchange, deleting current session and re-raising")
ShopifyApp::SessionRepository.expects(:delete_session).with("session-id")
"with token exchange, re-raising error")

reraised_error = assert_raises ShopifyAPI::Errors::HttpResponseError do
with_token_refetch(@session, @id_token) do
Expand Down

0 comments on commit 6736026

Please sign in to comment.