From de22ad000078b825750a8e74bf7fce87a7e42f98 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 14 Aug 2020 12:41:56 +0100 Subject: [PATCH 1/2] Fix flash error issues in checkout requests --- app/controllers/checkout_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 1dbffc71e1e..c0d835ced8c 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 + xhr_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 xhr_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 From 0fd163602dbb69576bb4a59ab766377237aa4750 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 17 Aug 2020 11:17:42 +0100 Subject: [PATCH 2/2] Rename method for clarity --- app/controllers/checkout_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index c0d835ced8c..c47b112359b 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -235,7 +235,7 @@ def action_failed_response render :edit end format.json do - xhr_flash_errors + discard_flash_errors render json: { errors: @order.errors, flash: flash.to_hash }.to_json, status: :bad_request end end @@ -250,7 +250,7 @@ def permitted_params PermittedAttributes::Checkout.new(params).call end - def xhr_flash_errors + 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.