Promise Reject Fallback
npm install promise-reject-fallbackyarn add promise-reject-fallback
You want to add a rejection handler to a Promise but you only want it to run if the consumer doesn't handle your promise rejection.
// Page 1fetchPosts.thenconsole.logposts// Page 2fetchPosts.thenconsole.logposts.catchshowDialogerror
You have a error handler on fetchPosts to globally handle an error, in this case we use alert.
This is great for Page 1 because we have a generic way of handling and displaying errors!
This is not great for Page 2 because now we have duplicated error handling, our catch handler
fetchPosts handles the rejection, but so does Page 2.
withFallback will decorate your Promise and allow you to add a fallback rejection handler
only if one wasn't added later in the chain.
// Page 1, alert Error!fetchPosts.thenconsole.logposts// Page 2, dialog with Error!fetchPosts.thenconsole.logposts.catchshowDialogerror