【发布时间】:2016-08-19 15:35:09
【问题描述】:
如果没有缓存,我正在编写一个 KOA 中间件来从 mongo 中提取用户信息。我收到以下错误:
“this.getUser”函数返回一个 ES6 承诺,如果未使用请求缓存或创建新的匿名用户,则从 mongo 获取用户。
module.exports = function* securityMiddleware(next) {
this.getUser(this.request)
.then((user)=>{
if(user.isAonymous){
//throw 401 access error
}else{
yield next;
}
});
};
这是无效的,因为:jshint 说生成器必须有一个 yield 并抛出一个 SyntaxError: Unexpected strict mode reserved word。
您如何在 KOA 中间件生成器中使用 Promise?我正在使用 KOA v1.2.0。
【问题讨论】:
标签: node.js promise yield es6-promise koa