I'm using Express.js in my code with Node.js v7.3. In this I've created a User Router
which forwards the requests to my User Controller
.
I'm using async/await inside the User Controller
to do asynchronous calls. The problem is that IntelliJ gives me a warning saying that
Promise returned from login() is ignored.
The thing is I'm not even returning anything from the login()
method.
Here's the code -
UserRouter.js
router.post('/login', function (req, res, next) {
userController.login(req, res); // I get the warning here
});
UserController.js
exports.login = async function (req, res) {
try {
const verifiedUser = await someFunction(req.body.access_code);
let user = await User.findOrCreateUser(verifiedUser);
res.status(200).send(user);
}
catch (err) {
res.status(400).send({success: false, error: err});
}
};
If I write the same login method using native promises only then I don't get this warning. Am I understanding something wrong here or is IntelliJ at fault?
EDIT -
Thanks to @Stephen, I understand that an async function returns a promise but wouldn't it be better if Intellij identifies that nothing is being returned from the async function and doesn't show that warning because when I chain a .then()
after the login()
function, it provides an undefined
object into the then result. It means if we don't return something from the async function explicitly then undefined is returned?