Why does the following code report an Uncaught (in promise) rejected error when it is being caught?
function Test() {
this.start = function(action) {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (action == "fail") return reject("rejected");
resolve("resolved");
}, 1000);
});
}
}
const test = new Test();
const promise = test.start("fail");
promise.then(console.log);
promise.catch(console.error);
The output (in a browser) is:
rejected from the catch()
Uncaught (in promise) rejected from the call to reject