//表单数据验证规则--controller/uer.js
const createRule={
name:{type:'string',required: true, allowEmpty: false,min:5,max:32},
password:{type: 'password', required: true, allowEmpty: false, min: 6},
email:{type: 'email', required: true, allowEmpty: false}
};
//对表单数据进行校验
try{
ctx.validate(createRule);
}
catch(err){
ctx.body=err;
return;
}
打印出的error:
{"message":"Validation Failed","code":"invalid_param","errors":[{"message":"length should bigger than 5","code":"invalid","field":"name"},{"message":"should not be empty","code":"invalid","field":"password"}]}
我想把上面errors中的message改成中文,请问在哪里改呢?或者怎么配置?
Most helpful comment
确实需要自定义错误信息.