Show more specific message for oauth errors

I forgot how hard it is to do view stuff in controllers.
I tried using the short lazy-lookup key '.oauth_error_html', which is supposed to work in controllers. But perhaps it doesn't work within a rescue?
This commit is contained in:
David Cook
2025-01-21 16:08:01 +11:00
parent 4ce2730bf0
commit 4c84fdf7f1
3 changed files with 16 additions and 4 deletions

View File

@@ -35,10 +35,18 @@ module Admin
end
@count = imported.compact.count
rescue Rack::OAuth2::Client::Error => e
flash[:error] = I18n.t(
'admin.dfc_product_imports.index.oauth_error_html',
message: e.message,
oidc_settings_link: ActionController::Base.helpers.link_to(
I18n.t('spree.admin.tab.oidc_settings'), Rails.application.routes.url_helpers.admin_oidc_settings_path
)
).html_safe
redirect_to admin_product_import_path
rescue Faraday::Error,
Addressable::URI::InvalidURIError,
ActionController::ParameterMissing,
Rack::OAuth2::Client::Error => e
ActionController::ParameterMissing => e
flash[:error] = e.message
redirect_to admin_product_import_path
end

View File

@@ -849,6 +849,7 @@ en:
index:
title: "Importing a DFC product catalog"
imported_products: "Imported products:"
oauth_error_html: "Authentication error: %{message}. See %{oidc_settings_link}"
enterprise_fees:
index:
title: "Enterprise Fees"

View File

@@ -91,8 +91,11 @@ RSpec.describe "DFC Product Import" do
click_button "Import"
expect(page).to have_content "invalid_grant"
expect(page).to have_content "session not active"
within ".flash" do
expect(page).to have_content "invalid_grant"
expect(page).to have_content "session not active"
expect(page).to have_link "OIDC Settings"
end
end
it "fails gracefully" do