By default, an instance of Promise
without .catch(onReject)
will throw an exception while it is rejected. promiseRejectionAutoHandle will catch the exception automatically in such situations.
const handler = (err) => console.log(err);
require('jinang/promiseRejectionAutoHandle')(handler);
// The *handler* is not required
new Promise((resolve, reject) => { /* ... */ })
.then(data => {
/* ... */
})
;
Read unit test code for more examples.