Reputation: 2165
Heres my code:
var delete_card = function(){
stripe.customers.deleteCard(
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
Both the stripe call and the save call return promises.
How would I RETURN a promise from the delete_card method?
Would I wrap them all in like new Promise and return a promise from there?
How would I structure that so I bubble up both errors and results?
I want to be able to do something from the caller like this:
delete_card
.then(...)
.catch(...)
And just keep composing chained promises?
Upvotes: 2
Views: 77
Reputation: 26877
Just return the promise in the delete_card
function.
var delete_card = function(){
/************/
/**/return/**/ stripe.customers.deleteCard(
/************/
this.service_id.stripe,
this.credit_card[0].stripe_id
)
.then(function(obj){
this.recipients.splice(0, 1);
return this.save()
})
}
Edit: I made it obnoxiously obvious where to add the return
since the code difference is so subtle.
Upvotes: 5