I am new to UnhandledRejection. The below method is supposed to throw exception and terminate flow but it doesn't.Please favour on resolving it either way
Case 1: Took value from promise as true and tried conditions.But it is bypassed and returns unhandled rejection with the exception to be thrown.
Utils.isMaximumLimitReached(id).then(isLimit=>{
console.log(isLimit); //true
if(isLimit){
throw "not allowed";
}
})
Edit: Case 3:This too returns Unhandled rejection this is not allowed
const isMaximumLimitReached = coachingId => {
return db.coachingClassEntries
.findAndCountAll()
.then(counts => {
let numberOfEntries = 2;
//let maxEntries = counts.rows[0].coachingClass.maxEntries;
let maxEntries=2;
return new Promise((resolve,reject)=>{
if (numberOfEntries == maxEntries) {
reject('this is not allowed');
}
});
});
};
Utils.isMaximumLimitReached(data.coachingClassId).then().catch(error=>{
throw error;
})