Promise: Ignore Catch and Return to Chain

Adam Halasz

Is it possible to ignore a catch and return back to the chain?

promiseA()        // <-- fails with 'missing' reason
  .then(promiseB) // <-- these are not going to run 
  .then(promiseC)
  .catch(function(error, ignore){
     if(error.type == 'missing'){
        ignore()  // <-- ignore the catch and run promiseB and promiseC
     }
  })

Is something like this possible?

Madara's Ghost

Here's the synchronous analogy:

try {
  action1(); // throws
  action2(); // skipped
  action3(); // skipped
} catch (e) {
  // can't resume
}

vs

try {
  action1(); // throws
} catch (e) {
  handleError(e);
}
action2(); // executes normally
action3();

Here's the promise version:

asyncActionA()        // <-- fails with 'missing' reason
.catch(error => {
   if(error.type == 'missing'){
      return; // Makes sure the promise is resolved, so the chain continues
   }
   throw error; // Otherwise, rethrow to keep the Promise rejected
})
.asyncActionB(promiseB) // <-- runs
.asyncActionC(promiseC)
.catch(err => {
  // Handle errors which are not of type 'missing'.
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Promise catch() order in complex promise return chain

From Dev

Define fallback catch for promise chain?

From Dev

How does the 'catch' work in a native Promise chain?

From Dev

Scala: Ignore Future return value, but chain them

From Dev

How to fix the return type of the last promise in a chain?

From Dev

How to return promise.map (bluebird) inside a promise chain?

From Dev

In the Promise of Javascript, why can't the error be passed to the next chain `.catch()`?

From Dev

How to return from a Promise's catch/then block?

From Dev

How to return the promise then()/catch() result to the function containing the promise?

From Dev

Chain of promise

From Dev

How to chain a RSVP promise and return the original reject/success functions?

From Java

Vuex: Does dispatch return a promise so that you can chain them?

From Dev

return value inside promise chain isn't getting called

From Dev

ExpressJS / NodeJS / Promises: Return early from promise chain

From Dev

return response for module.export from promise chain function

From Dev

What's the best way to return multiple values in a promise chain

From Dev

How Can I Test a .catch Promise Return in AngularJS using Jasmine?

From Dev

Return only innermost promise's catch and handle others

From Java

How does Promise chain work when one callback doesn't return any promise?

From Dev

How can I release a resource in a nodeJS Q promise-chain and return a promise?

From Dev

Chain commands and ignore error

From Dev

Ending a Promise chain

From Dev

Promise chain fundamental issue

From Dev

Promise chain inside for loop

From Dev

Cancel a promise chain?

From Java

using setTimeout on promise chain

From Dev

Creating an error in promise chain

From Dev

Breaking up promise chain

From Dev

Reject promise in the chain

Related Related

  1. 1

    Promise catch() order in complex promise return chain

  2. 2

    Define fallback catch for promise chain?

  3. 3

    How does the 'catch' work in a native Promise chain?

  4. 4

    Scala: Ignore Future return value, but chain them

  5. 5

    How to fix the return type of the last promise in a chain?

  6. 6

    How to return promise.map (bluebird) inside a promise chain?

  7. 7

    In the Promise of Javascript, why can't the error be passed to the next chain `.catch()`?

  8. 8

    How to return from a Promise's catch/then block?

  9. 9

    How to return the promise then()/catch() result to the function containing the promise?

  10. 10

    Chain of promise

  11. 11

    How to chain a RSVP promise and return the original reject/success functions?

  12. 12

    Vuex: Does dispatch return a promise so that you can chain them?

  13. 13

    return value inside promise chain isn't getting called

  14. 14

    ExpressJS / NodeJS / Promises: Return early from promise chain

  15. 15

    return response for module.export from promise chain function

  16. 16

    What's the best way to return multiple values in a promise chain

  17. 17

    How Can I Test a .catch Promise Return in AngularJS using Jasmine?

  18. 18

    Return only innermost promise's catch and handle others

  19. 19

    How does Promise chain work when one callback doesn't return any promise?

  20. 20

    How can I release a resource in a nodeJS Q promise-chain and return a promise?

  21. 21

    Chain commands and ignore error

  22. 22

    Ending a Promise chain

  23. 23

    Promise chain fundamental issue

  24. 24

    Promise chain inside for loop

  25. 25

    Cancel a promise chain?

  26. 26

    using setTimeout on promise chain

  27. 27

    Creating an error in promise chain

  28. 28

    Breaking up promise chain

  29. 29

    Reject promise in the chain

HotTag

Archive