From c9d14147eba9a7fc0693256e825d8112d9dc76ca Mon Sep 17 00:00:00 2001 From: Nabeel Ahsen Date: Mon, 25 Jan 2021 14:39:52 -0500 Subject: [PATCH] Add logging before redirect --- .../concerns/shopify_app/ensure_authenticated_links.rb | 4 +++- .../concerns/ensure_authenticated_links_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb index 252ccdf23..8c182b89c 100644 --- a/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +++ b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb @@ -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.debug("[ShopifyApp::EnsureAuthenticatedLinks] Redirecting to login: [#{error.class}] "\ + "Could not determine current shop domain") redirect_to(ShopifyApp.configuration.login_url) end diff --git a/test/controllers/concerns/ensure_authenticated_links_test.rb b/test/controllers/concerns/ensure_authenticated_links_test.rb index d8bc9935e..ad009d7ad 100644 --- a/test/controllers/concerns/ensure_authenticated_links_test.rb +++ b/test/controllers/concerns/ensure_authenticated_links_test.rb @@ -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(:debug).once.with(expected_message) + end end