Rescue from invalid DFC catalog URLs

This mistake should be dealt with differently but I wanted to make sure
that a really invalid URL is handled well, too.
This commit is contained in:
Maikel Linke
2025-02-25 15:49:54 +11:00
parent 5bef8b7dde
commit b6153fc155
3 changed files with 12 additions and 0 deletions

View File

@@ -27,6 +27,9 @@ module Admin
@enterprise.supplied_variants.linked_to(subject.semanticId)&.product
]
end
rescue URI::InvalidURIError
flash[:error] = t ".invalid_url"
redirect_to admin_product_import_path
rescue Faraday::Error,
Addressable::URI::InvalidURIError,
ActionController::ParameterMissing => e

View File

@@ -862,6 +862,7 @@ en:
one: "1 selected"
other: "%{count} selected"
import: Import
invalid_url: This catalog URL is not valid.
import:
title: "DFC product catalog import"
imported_products: "Imported products:"

View File

@@ -22,7 +22,15 @@ RSpec.describe "DFC Product Import" do
# We are testing against our own catalog for now but we want to replace
# this with the URL of another app when available.
# We also add a common mistake: copying the URL with an extra space.
host = Rails.application.default_url_options[:host]
url = " http://#{host}/api/dfc/enterprises/#{enterprise.id}/catalog_items"
fill_in "catalog_url", with: url
select enterprise.name, from: "Create products for enterprise"
click_button "Preview"
expect(page).to have_content "This catalog URL is not valid"
url = "http://#{host}/api/dfc/enterprises/#{enterprise.id}/catalog_items"
fill_in "catalog_url", with: url
select enterprise.name, from: "Create products for enterprise"