function function1() {
return new Promise((resolve, reject) => {
console.log("http request");
resolve();
});
}
function function2(error) {
return new Promise((resolve, reject) => {
if (error) throw new Error('invalidate cache error!');
console.log("invalidate cache");
resolve();
});
}
console.log("------------------- INCORRECT ERROR HANDLING ------------------------");
function1()
.then(() => {
function2(true);
})
.catch(err => console.error("ERROR!!!", err.message));
console.log("-------------------- CORRECT ERROR HANDLING -------------------------");
function1()
.then(() => function2(true))
.catch(err => console.error("ERROR!!!", err.message));
console.log("------------------------------ FIN ----------------------------------");
To embed this project on your website, copy the following code and paste it into your website's HTML: