I am stuck on this problem, I have create a function in NodeJS application when I am hitting the API getting this error.
(node:14872) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
at ServerResponse.writeHead (_http_server.js:255:11)
at ServerResponse.writeHead (C:\Users\Ishan\Main\node_modules\on-headers\index.js:44:26)
at ServerResponse._implicitHeader (_http_server.js:246:8)
at write_ (_http_outgoing.js:685:9)
at ServerResponse.end (_http_outgoing.js:798:5)
at ServerResponse.send (C:\Users\Ishan\Main\node_modules\express\lib\response.js:221:10)
at ServerResponse.json (C:\Users\Ishan\Main\node_modules\express\lib\response.js:267:15)
at C:\Users\Ishan\Main\server\api\v1.0\user\index.js:28:35
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:14872) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:14872) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
this is the function
let insertTo = ()=> {
return new Promise((resolve, reject) => {
UserModel.find({"emailVerification.status":true}).aggregate([
{
'$lookup':
{
'from':'unitDetails',
'localField' :'_id',
'foreignField':'customerID',
'as':'cusId'
}
},{
$unwind: "$cusId"
}]).then((result)=>{
if(result !== null){
resolve({ status: true, statusCode: 200, message: "User list fetched",data:result});
} else {
reject({ status: false, statusCode: 400, message: "Invalid request", error: "Bad request" });
};
}).catch((err)=>{
reject({ status: false, statusCode: 500, message: "Internal server error", error: "Bad request" });
})
})
}