Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to chain promise error functions in angularjs

I know how to chain promises so that multiple success functions are executed. That is esplained in many examples. How do I chain promises so that multiple error functions are executed?

like image 365
Galdor Avatar asked Apr 13 '15 06:04

Galdor


1 Answers

When an error is handled (and, either a value is returned or no value at all), the promise returned from then is considered resolved. You have to return a rejected promise from each error handler in order to propagate and chain error handlers.

For example:

promseA.then(
   function success() {
   },
   function error() {
      return $q.reject();
   })
.promiseB.then(
   function success() {
   },
   function error() {
      return $q.reject();
   })
.promiseC.then(
   function success() {
   },
   function error() {
      return $q.reject();
   });
like image 199
pixelbits Avatar answered Sep 17 '22 23:09

pixelbits