2

I have a promise chain which requires rejection to be handled differently for individual steps:

serviceA.getData()
    .then(
        function(dataA) {
            return serviceB.getData(dataA);
        }, function(err) {
            res.status(404).end();
        }
    )
    .then(
        function(dataB) {
            return serviceC.getData(dataB);
        }, function(err) {
            res.status(401).end();
        }
    )
    .done();

When serviceA.getData() promise is rejected, I want promise chain to be interrupted after first rejection handler executes. Instead, both rejection handlers get executed.

Couldn't find an answer in Q docs. Suggestions?

Arnold Zokas
  • 8,306
  • 6
  • 50
  • 76
  • That's the way promises are supposed to work, you could place your code in a `try-catch` block and pass information about the kind of error that happened to the outer (try catch) code from within your rejection handlers by `throw`ing exceptions. – Hrishi Oct 20 '14 at 16:41
  • 1
    maybe also see [Break promise chain and call a function based on the step in the chain where it is broken](http://stackoverflow.com/q/20714460/1048572) – Bergi Oct 20 '14 at 16:50

0 Answers0