我正在使用风帆(v0.11)
我已在我的应用程序中安装了sails-hook-validation
。
validationMessages: {
email: {
required: 'Email is required',
email: 'Provide valid email address',
unique: 'Email address is already taken'
},
username: {
required: 'Username is required'
}
}
并将上述代码添加到我的模型中。
如果发送无效email
{
"error": "E_VALIDATION",
"status": 400,
"summary": "1 attribute is invalid",
"model": "User",
"invalidAttributes": {
"email": [
{
"rule": "email",
"message": "`undefined` should be a email (instead of \"vishnu@ad\", which is a string)"
}
]
},
"Errors": {
"email": [
{
"rule": "email",
"message": "Provide valid email address"
}
]
}
}
当您看到错误消息时,我同时收到invalidAttributes
和Errors
。如何删除invalidAttributes
?
如何在我的风帆应用中配置以删除invalidAttributes
?
答案 0 :(得分:1)
修改响应文件夹中的badRequest.js。
例如:
```//remove unnecessary keys if debug is false
if(process.env.APP_DEBUG === 'false'){
delete data.stack;
delete data.rawStack;
delete data.details;
delete data.message;
delete data.model;
delete data._e;
delete data.reason;
}```