0

I have some code that uses .success() .error() so I need to migrate that. The question is, is .then() and .catch() the same idea? Most examples I see have then(successFunction, errorFunction) but with the layout it's just easier to change to .then() for .success() and .catch() for .error() assuming, which is the question here, that gives the same behavior. It seems to but does anyone know of any possible issues with using .catch() vs the error function in .then()?

user441521
  • 6,942
  • 23
  • 88
  • 160
  • @Igor I looked through that and didn't see an explanation of exactly is .catch() gives the same behavior in all situations as .then(success, error). – user441521 May 18 '18 at 14:45
  • @Igor That's a little better. Still seems a little vague given the explanation given but helps some. – user441521 May 18 '18 at 14:54
  • Read [Promise : then vs then + catch](https://stackoverflow.com/questions/33278280/promise-then-vs-then-catch). The short answer is that `.catch` will catch errors in the success handler of the `.then` while the rejection handler of the `.then` will not. – georgeawg May 18 '18 at 15:26
  • @georgeawg Thanks for that. The question is does catch() also catch the errors from the promise itself just like the error handle does in then()? If so the catch() acts as 1 way to catch errors in 2 different locations of where the error happened? – user441521 May 18 '18 at 19:11
  • 1
    `.catch` will catch not just the two locations but from rejections from all the previous promises in the promise chain. Read [Angular execution order with `$q` — Chaining Promises](https://stackoverflow.com/questions/34324153/angular-execution-order-with-q-chaining-promises/34326388#34326388). – georgeawg May 18 '18 at 19:50

0 Answers0