需要自定义错误消息,而应使用Joi中的默认消息。
const schema = {
email: Joi.string().email().label("Email Address"),
password: Joi.string()
}
答案 0 :(得分:0)
这是我的答案,但是我仍然需要多种语言来编写自定义消息。
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()
}