From 47a93568dcecfcd03b164848ed7fd890ae85c164 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 14 Apr 2020 13:55:20 +0100 Subject: [PATCH] Make code simpler by extracting methods --- .../darkswarm/services/checkout.js.coffee | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/checkout.js.coffee b/app/assets/javascripts/darkswarm/services/checkout.js.coffee index d974004d92..3b7c2756d7 100644 --- a/app/assets/javascripts/darkswarm/services/checkout.js.coffee +++ b/app/assets/javascripts/darkswarm/services/checkout.js.coffee @@ -19,19 +19,24 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE Navigation.go response.data.path .catch (response) => try - if response.data.path - Navigation.go response.data.path - else - throw response unless response.data.errors || response.data.flash - - Loading.clear() - @errors = response.data.errors - RailsFlashLoader.loadFlash(response.data.flash) + @handle_checkout_error_response(response) catch error - Loading.clear() - RailsFlashLoader.loadFlash(error: t("checkout.failed")) # inform the user about the unexpected error + @loadFlash(error: t("checkout.failed")) # inform the user about the unexpected error throw error # generate a BugsnagJS alert + handle_checkout_error_response: (response) => + if response.data.path + Navigation.go response.data.path + else + throw response unless response.data.errors || response.data.flash + + @errors = response.data.errors + @loadFlash(response.data.flash) + + loadFlash: (flash) => + Loading.clear() + RailsFlashLoader.loadFlash(flash) + # Rails wants our Spree::Address data to be provided with _attributes preprocess: -> munged_order =