From 00ac1c7d9e914f7b48706b0adba66ea0914159be Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 27 Jun 2024 11:38:44 +1000 Subject: [PATCH] Update controller to catch more specific error We now know which errors to expect. We still let other unknown errors raise higher up, where they will be logged with BugSnag, and treated as internal_server_error. --- app/controllers/admin/products_v3_controller.rb | 4 ++-- spec/lib/spree/core/product_duplicator_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index f5baaf310c4c..28f352009ff4 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -82,9 +82,9 @@ def clone @producer_options = producers @category_options = categories @tax_category_options = tax_category_options - rescue StandardError => _e + rescue ActiveRecord::ActiveRecordError => _e flash.now[:error] = t('.error') - status = :internal_server_error + status = :unprocessable_entity @product_index = "-1" # Create a unique enough index end diff --git a/spec/lib/spree/core/product_duplicator_spec.rb b/spec/lib/spree/core/product_duplicator_spec.rb index 2ea637e4acb4..141030048a85 100644 --- a/spec/lib/spree/core/product_duplicator_spec.rb +++ b/spec/lib/spree/core/product_duplicator_spec.rb @@ -106,7 +106,9 @@ } subject { Spree::Core::ProductDuplicator.new(product).duplicate } - it "returns an invalid record" + it "raises RecordInvalid error" do + expect{ subject }.to raise_error(ActiveRecord::RecordInvalid) + end end context "invalid variant" do