Skip to content

Commit

Permalink
Add logging before redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
NabeelAhsen committed Jan 25, 2021
1 parent 3e290e9 commit 551fff6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module EnsureAuthenticatedLinks
def redirect_to_splash_page
splash_page_path = root_path(return_to: request.fullpath, shop: current_shopify_domain)
redirect_to(splash_page_path)
rescue ShopifyApp::LoginProtection::ShopifyDomainNotFound
rescue ShopifyApp::LoginProtection::ShopifyDomainNotFound => error
Rails.logger.warn("[ShopifyApp::EnsureAuthenticatedLinks] Redirecting to login: [#{error.class}] "\
"Could not determine current shop domain")
redirect_to(ShopifyApp.configuration.login_url)
end

Expand Down
8 changes: 8 additions & 0 deletions test/controllers/concerns/ensure_authenticated_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ def current_shopify_domain

test 'redirects to login page if current shopify domain is not found' do
@controller.expects(:current_shopify_domain).raises(ShopifyApp::LoginProtection::ShopifyDomainNotFound)
expect_redirect_error(ShopifyApp::LoginProtection::ShopifyDomainNotFound, "Could not determine current shop domain")

get :some_link

assert_redirected_to ShopifyApp.configuration.login_url
end

private

def expect_redirect_error(klass, message)
expected_message = "[ShopifyApp::EnsureAuthenticatedLinks] Redirecting to login: [#{klass}] #{message}"
Rails.logger.expects(:warn).once.with(expected_message)
end
end

0 comments on commit 551fff6

Please sign in to comment.