My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Explanation | Checking if all promises fail?

Arihant's photo
Arihant
·Mar 12, 2019

I'm reading Service Worker Offline Cookbook. Following is a piece of code, that checks if all promises have rejected —

/*  inside a promise */
/* reject if all promises reject */

promises.reduce((a, b) => a.catch(() => b))
    .catch(() => reject(Error('All Failed'))

I do not understand how a.catch(() => b) inside a reduce is ensuring to tell the information of failure of promises.