【发布时间】:2018-06-27 15:51:16
【问题描述】:
所以我使用 JOI 编写模式验证。 https://github.com/hapijs/joi
我想对抛出的错误的行为做一个小的改变。
这是我现在遇到的错误:
[
{
"name": "api_schema",
"message": "\"architect\" with value \"Someasda2342432ssda\" fails to match the required pattern: /^[a-zA-Z_ ]{2,50}$/"
}
]
但我想收到的是:
[
{
"name": "api_schema",
"message": "\"api_config.team_info.architect\" with value \"Someasda2342432ssda\" fails to match the required pattern: /^[a-zA-Z_ ]{2,50}$/"
}
]
如您所见,我需要错误消息指示失败密钥的所有路径,而不仅仅是其名称。我知道 JOI 具有自定义错误消息的能力,并且我可以这样做,但是我没有找到一种方法来获取失败键的整个路径的值。
有人可以建议吗?
【问题讨论】:
标签: node.js schema customization joi