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