mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make code simpler by extracting methods
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user