When i tried using .then() after an asynchronous function, I get the following error:
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)
I am trying to use it in a server side application. When the client side requests for credential validation, my application checks whether the data received exists in the Mongo DB.
app.post('/checkUserDetails',(req,res)=>{
console.log("request: ",req.body);
UserDetail.findOne({username: req.body.username, password: req.body.password}).then(function(result,done){
if(result==undefined){
res.send({"status": "succesfull, Welcome Admin !!!"});
done();
}
else{
res.send({"status": "Password or id wrong"});
done();
}
});
});