node.js - Bluebird - how to propagate errors in nested promise -
promisea().then(function(){ promiseb().catch(function (e) { throw e; }) }).catch(function (e) { // want exceptions thrown in nested promise chain end here. })
how exceptions nested promises bubble parent promise?
use return
keyword,
your code can simplified as:
promisea().then(function(){ return promiseb(); }).catch(function (e) { // want exceptions thrown in nested promise chain end here. })
edit:
not sure if right way, if promise cancellation involved , want bubble error flow, can wrap promise in custom promise never resolves throws error( if happens):
promisea().then(function(){ var mypromise = promiseb().then...; return new promise(function(resolve, reject){ mypromise.catch(reject) }) }).catch(function (e) { // want exceptions thrown in nested promise chain end here. })
Comments
Post a Comment