Make code simpler by extracting methods

This commit is contained in:
Luis Ramos
2020-04-14 13:55:20 +01:00
parent 62471bf2ab
commit 47a93568dc

View File

@@ -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 =