gpt4 book ai didi

node.js - 删除 sails 中无效的属性

转载 作者:太空宇宙 更新时间:2023-11-03 22:14:49 25 4
gpt4 key购买 nike

我使用的是 sails(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'
}
}

并将上述代码添加到我的模型中。

如果我发送无效的电子邮件,我会收到以下错误消息

{
"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"
}
]
}
}

正如您看到的错误消息,我同时收到 invalidAttributesErrors。如何删除invalidAttributes

我应该如何在我的 sails 应用程序中进行配置以删除 invalidAttributes

最佳答案

修改response文件夹中的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;
}```

关于node.js - 删除 sails 中无效的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32338283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com