mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user