For example, making two calls with fetch()
(second one inside the .then()), do you need two .catch()
or only the outside one is enough?
I have tried to replicate but couldn't so far.
b = new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Solving...');
resolve('solved');
}, 3000);
})
.then(() => {
new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Rejecting...');
reject('error');
}, 1000);
})
.then(() => null)
.catch((error) => {
console.log('Catching error inside.');
console.log(error);
});
})
.catch((error) => {
console.log('Catching error outside.');
console.log(error);
});
This works, but if I remove the inner catch()
I get Unhandled promise rejection
error
Solving...
Rejecting...
(node:73650) UnhandledPromiseRejectionWarning: error
(node:73650) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:73650) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.