created a nodejs module called role-management, and I published it in azure artifacts(the equivalent of npm repository).
here's the code of this model :
const mongoose = require('mongoose');
exports.getRoles = async (db_url,key) => {
await mongoose.connect(db_url, { useNewUrlParser: true });
const UserSchema= new mongoose.Schema({ },{ strict: false });
const User = mongoose.model('User', UserSchema,'users');
const result = await User.find({ $or: [{ name: key }, { email: key }] });
console.log(result[0].roles)
return result[0].roles
}
I tried to install this module on my project, here's the code which use this module :
const getRoles=required('role-management')
const getItems = async (req, res) => {
try {
const roles = await getRoles(
process.env.db-url,
req.Email
)
res.status(200).json(roles)
} catch (error) {
handleError(res, error)
}
}
module.exports = { getItems }
now the problem is, when I try to hit getItem from an api the first time, it works and i'm getting the roles, but when I try the second time i got this error :
(node:21540) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
is there something wrong with the role-management module ? mongoose connectivity problem ? could help please ?