在 JSON 中制作 ctx.assert 响应

问题描述

我的代码中有几个 ctx.assert,例如:

ctx.assert(db && fb && ObjectId,400,'Email validation config error')

如果该断言失败,我的响应将是“电子邮件验证配置错误”为 string,但我想在 JSON 中得到响应,我尝试过类似的操作,但没有工作:

ctx.assert(db && fb && ObjectId,{error: 'Email validation config error'})

有没有办法让 ctx.assert 的响应在 JSON 中?

解决方法

ctx.assert(db && fb && ObjectId,400,JSON.stringify({error: 'Email validation config error'}))