我对mongoose很新,所以我想知道是否有某种方法来设置custom error message
而不是默认的方式Validator "required" failed for path password
.
我想设置一些Password is required.
更加用户友好的东西.
我写了一些自定义验证器并type
使用此用户友好的错误消息设置属性,但我不确定type
是错误消息的正确占位符.也没有办法在预定义的验证器上设置自定义消息min, max, required, enum...
一种解决方案是检查每次type
抛出错误的属性并手动分配错误消息,但认为这是验证者的工作:
save model
if error
check error type (eg. "required")
assign fancy error message (eg. "Password is required.")
Run Code Online (Sandbox Code Playgroud)
这显然不是理想的解决方案.
我查看了express-form和node-validator,但仍想使用mongoose验证功能.