Merge pull request #4699 from mkllnk/4696-rescue-checkout

Rescue unknown checkout errors
This commit is contained in:
Luis Ramos
2020-01-24 18:11:38 +00:00
committed by GitHub
3 changed files with 16 additions and 0 deletions

View File

@@ -68,6 +68,13 @@ class CheckoutController < Spree::CheckoutController
render json: { path: order_path(@order) }, status: :ok
end
end
rescue Spree::Core::GatewayError => error
# This is done for all actions in the Spree::CheckoutController.
rescue_from_spree_gateway_error(error)
rescue StandardError => error
Bugsnag.notify(error)
flash[:error] = I18n.t("checkout.failed")
update_failed
end
# Clears the cached order. Required for #current_order to return a new order

View File

@@ -1180,6 +1180,7 @@ en:
already_ordered:
cart: "cart"
message_html: "You have an order for this order cycle already. Check the %{cart} to see the items you ordered before. You can also cancel items as long as the order cycle is open."
failed: "The checkout failed. Please let us know so that we can process your order."
shops:
hubs:
show_closed_shops: "Show closed shops"

View File

@@ -200,6 +200,14 @@ describe CheckoutController, type: :controller do
expect(response.body).to eq({ path: spree.order_path(order) }.to_json)
end
it "returns an error on unexpected failure" do
allow(order).to receive(:update_attributes).and_raise
spree_post :update, format: :json, order: {}
expect(response.status).to eq(400)
expect(response.body).to eq({ errors: {}, flash: {error: I18n.t("checkout.failed")} }.to_json)
end
describe "stale object handling" do
it "retries when a stale object error is encountered" do
allow(ResetOrderService).to receive(:new).with(controller, order) { reset_order_service }