diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 1dbffc71e1e..c47b112359b 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -235,6 +235,7 @@ def action_failed_response render :edit end format.json do + discard_flash_errors render json: { errors: @order.errors, flash: flash.to_hash }.to_json, status: :bad_request end end @@ -248,4 +249,11 @@ def rescue_from_spree_gateway_error(error) def permitted_params PermittedAttributes::Checkout.new(params).call end + + def discard_flash_errors + # Marks flash errors for deletion after the current action has completed. + # This ensures flash errors generated during XHR requests are not persisted in the + # session for longer than expected. + flash.discard(:error) + end end