Skip to content

Commit

Permalink
Switch from old success/error to modern then/catch structure
Browse files Browse the repository at this point in the history
Catch() will get a few more errors then errors()

Also, add try/catch inside catch to detect any errors parsing the
response error payload
  • Loading branch information
luisramos0 committed Apr 10, 2020
1 parent b92e858 commit 2ce1f5b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/assets/javascripts/darkswarm/services/checkout.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE

submit: =>
Loading.message = t 'submitting_order'
$http.put('/checkout.json', {order: @preprocess()}).success (data, status)=>
Navigation.go data.path
.error (response, status)=>
if response.path
Navigation.go response.path
else
Loading.clear()
@errors = response.errors
RailsFlashLoader.loadFlash(response.flash)
$http.put('/checkout.json', {order: @preprocess()})
.then (response) ->
Navigation.go response.data.path
.catch (response) ->
try
if response.data.path
Navigation.go response.data.path
else
Loading.clear()
@errors = response.data.errors
RailsFlashLoader.loadFlash(response.data.flash)
catch error
RailsFlashLoader.loadFlash("Unkown error occurred")
Bugsnag.notifyException(error);

# Rails wants our Spree::Address data to be provided with _attributes
preprocess: ->
Expand Down

0 comments on commit 2ce1f5b

Please sign in to comment.