Open gaochengyidlmu opened 5 years ago
在 lib/Action.js 240 compose 方法中,给 beforeRespond 添加默认处理方式:
compose(hooks) {
hooks = hooks || {};
let stack = []
.concat(this.skipHooks ? [] : (hooks.before || []))
.concat(this.handler)
.concat(this.skipHooks ? [] : (hooks.after || []));
let errorHandler = utils.compose(hooks.error || []);
this.stack = utils.compose(stack, errorHandler);
hooks.beforeRespond = hooks.beforeRespond || [];
if (hooks.beforeRespond.length === 0) hooks.beforeRespond.push((ctx) => ctx.result);
this.beforeRespondStack = utils.compose(hooks.beforeRespond, errorHandler);
}
或者在 229 行的 invokeBeforeRespond 中判断 beforeRespond 的 hook 数量。
调用时,返回的是空数据。
在 lib/contexts/express.js 92 行,
data = await this.action.invokeBeforeRespond(ctx);
重新赋值 data 后,值为 undefined