Skip to content

Commit

Permalink
Update controller to catch more specific error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dacook committed Jun 27, 2024
1 parent 70f4d48 commit 00ac1c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/products_v3_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion spec/lib/spree/core/product_duplicator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00ac1c7

Please sign in to comment.