我创建了一个node.js Web应用程序。目前,我在数据库中使用MSSQL。我创建了函数(sql.js)来执行相应的SQL函数。我还创建了一个异步函数处理程序(controllers.js),以便可以在路由器(快速)中使用async和await关键字。路由器使用await关键字调用它们。我调用这些函数没有任何错误,实际上所有内容都返回数据并正常运行,但是在我的文本编辑器(VSCode)中,出现以下错误
[eslint] Parsing error: Unexpected token =>
经过进一步的调查,发现在我的控制台中我收到未处理的promise错误。这让我觉得我对控制器的定义不正确
internal/process/warning.js:18 (node:16328) Warning: a promise was created in a handler at D:\Programs\ColdFusion2016\cfusion\wwwroot\vue_starter\node_modules\express\lib\router\index.js:335:12 but was not returned from it, see http:// goo.gl/ rRqMUw
at Function.Promise.attempt.Promise.try (D:\Programs\ColdFusion2016\cfusion\wwwroot\vue_starter\node_modules\bluebird\js\release\method.js:29:9)
。有人看到控制器有问题吗?
router.js
const express = require('express');
const router = express.Router();
const {
asyncGet,
asyncPost
} = require('../services/controllers')(router);
const sql = require('../services/sql');
const request = require('../services/request');
/// Get Users
asyncGet('/controller/getUsers', async(req, res, next) => {
console.log('get: /controller/getUsers');
const users = await sql.getUsers();
res.status(200).json(users);
});
/// Get Products
asyncGet('/controller/getProducts', async(req, res, next) => {
console.log('get: /controller/getProducts');
const products = await sql.getProducts();
res.status(200).json(products);
});
module.exports = router;
controllers.js
module.exports = (router) => {
const asyncGet = (route, handler) => {
return router.get(route, (req, res, next) => {
handler(req, res, next)
.catch(error => {
next(error);
});
});
};
const asyncPost = (route, handler) => {
return router.post(route, (req, res, next) => {
handler(req, res, next)
.catch(error => {
next(error);
});
});
};
return { asyncGet, asyncPost };
};
答案 0 :(得分:1)
为了使ESLint支持out <-c("bp", "fm.", "bmi")
groups <- c("abc.q", "def.q", "ofj.q")
,在ESLint配置中它支持should be enabled:
async..await