Koa系列-Response Transformation:koa-res
2019-04-01
字数统计:2.6k 字
阅读时长 ≈ 2 分钟
代码比较简单,干净。主要是控制responseBody的数据。
首先判断 options.custom
是不是一个函数,若不是则提示类型错误。
然后如果存在 ctx._returnRaw
为 true
,则直接返回 ctx.body
。
否则,
1 | const status = ctx.status |
如果应用运行错误,则在 ctx.body
中加入 statck: e.stack
。
配置了 options.debug = true
,则不显示 ctx.body.stack
。