【发布时间】:2019-03-15 19:14:12
【问题描述】:
需要自定义错误消息,而不是使用 Joi 中的默认值。
const schema = {
email: Joi.string().email().label("Email Address"),
password: Joi.string()
}
【问题讨论】:
需要自定义错误消息,而不是使用 Joi 中的默认值。
const schema = {
email: Joi.string().email().label("Email Address"),
password: Joi.string()
}
【问题讨论】:
这是我的答案,但我仍然需要多种语言来自定义消息。
const schema = {
email: Joi.string().email().label("Email Address").error(err => {
err.forEach(error => {
switch(error.type){
case "string.base":
error.message = "must be a string";
break;
case "string.email":
error.message = "must be an email";
break;
}
});
return err;
}),
password: Joi.string()
}
【讨论】: