0
Even thought I have returned an error why then block is executed ?
function func(state) { return new Promise((resolve, reject) => { if (state) { resolve("promise is resolved"); } else { reject("oops ! promise is rejected"); } }); } let promise = func(true); promise.then((data) => { console.log(data); return new Error('test') }).then((data) => { console.log(`success ${data}`); }).catch((err) => { console.log(err); })
1 Answer
0
Instead of returning an error, you should throw an error of course by using the throw keyword.