mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-04 07:09:14 +00:00
Switch from old success/error to modern then/catch structure
Catch() will get a few more errors then errors() Also, add try/catch inside catch to detect any errors parsing the response error payload
This commit is contained in:
@@ -14,15 +14,19 @@ 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")
|
||||
|
||||
# Rails wants our Spree::Address data to be provided with _attributes
|
||||
preprocess: ->
|
||||
|
||||
@@ -119,6 +119,7 @@ describe 'Checkout service', ->
|
||||
it "puts errors into the scope", ->
|
||||
$httpBackend.expectPUT("/checkout.json").respond 400, {errors: {error: "frogs"}}
|
||||
Checkout.submit()
|
||||
|
||||
$httpBackend.flush()
|
||||
expect(Checkout.errors).toEqual {error: "frogs"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user