我在Node.js v7的代码中使用Express.js.3.在这里,我创建了一个User Router,将请求转发给我的User Controller.

我在User Controller中使用async/await来进行异步调用.问题是IntelliJ给了我一个警告说

忽略从login()返回的promise .

问题是我甚至没有从login()方法中返回任何东西.

这是密码-

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});
    }
};

如果我只使用本机promise 编写相同的登录方法,那么我不会收到此警告.我是理解错了还是IntelliJ错了?

EDIT -

多亏了@Stephen,我明白异步函数会返回一个promise ,但如果Intellij识别出异步函数没有返回任何东西,并且没有显示该警告,那不是更好吗?因为当我在login()函数后链接.then()时,它会在随后的结果中提供一个undefined对象.这意味着,如果我们不显式地从异步函数返回某些内容,那么将返回undefined?

推荐答案

问题是,我甚至没有从login()方法返回任何内容.

声明为"async"的函数根据定义返回promise .

However the IDEA warning is only an inspection. You can press "alt-enter, right" on the warning and change the inspection level to make the warning go away. The inspection is in the "JavaScript -> Probable bugs" category and is named "Result of method call returning a promise is ignored".

Node.js相关问答推荐

如何更改node-soap时间戳持续时间和前置码?

Express 4.18正文解析

Sveltekit停靠的应用程序找不到从Build导入的包

DocuSign:调用createEntaine时,RequestJWTApplicationToken返回401 AUTHORIZATION_INVALID_TOKEN

NPM:一般的npm二进制依赖可以静态构建吗?

模块';"; node :流程&没有导出的成员';dlopen';

如何发送比特币BTC使用发送加密使用WIF密钥在 node ,js

如果我在 tsx 文件中使用了use client,ssr 会如何发生?

当API返回400状态代码时,使用Reactjs fetch获取错误消息

使用pm2启动服务器

如何使用包含条件正确分页的 sequelize 查询?

express cors request.body formData显示undefined

如何从哪个应用程序用户中找到在 Firebase 身份验证中进行身份验证的用户

错误:无法检测到网络(event="noNetwork",code=NETWORK_ERROR,version=providers/5.6.8)

discordjs如何添加所有意图/权限

在 Javascript 逻辑中访问 EJS 变量

Node.js 表达的 Error 对象expose 了哪些属性?

使用 Node.js 在内存中缓冲整个文件

如何undo撤消 Object.defineProperty 调用?

node 应用程序是否有任何独立的 gui 模块