1

What's the right way to break out of this chain? Like, if I'm in the catch, I don't want the following two thens to execute.

I used to have the catch last, but moved it up, thinking it might help. It didn't.

return axios
  .post(url, data)
  .catch(error => {
    const message = getBannerTextFailureMessage(liability, toStatus)
    dispatch(showBanner(message, bannerConstants.typeError))
  })
  .then(response => {
    return dispatch(updateLiabilitiesComplete())
  })
  .then(response => {
    const message = getBannerTextSuccessMessage(liability, toStatus)
    dispatch(showBanner(message, bannerConstants.typeSuccess))
  })
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Bob Horn
  • 33,387
  • 34
  • 113
  • 219

2 Answers2

1

.catch catches any previous parts of the promise chain and leaves following .thens without reject function after .catch uncatched (unless there is another .catch). It means that your chain is failing probably in one of .then when .catch is in the end of chain and probably throws promise error into console when you left it uncatched (.catch immediately after .post).

Just remove(temporary) .catch and find out in which part it fails - from console log.

bigless
  • 2,849
  • 19
  • 31
0

After resolving the promise catch is used to catch any error from any of the then block. So if you put a catch block after then, the first error from the which may occur from the previous then blocks will be caught. So using catch where you have used makes no sense, also the first then block gets the return value from the promise after being resolved.

In the catch block:

do console.log(error) to find out what error you get.

Also to retrieve the values from a Promise resolved functions use eventlisteners(to break the chaining).

Prajval M
  • 2,298
  • 11
  • 32