删除sails中的invalidAttributes

时间:2015-09-01 18:11:18

标签: node.js sails.js

我正在使用风帆(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"
      }
    ]
  }
}

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

如何在我的风帆应用中配置以删除invalidAttributes

1 个答案:

答案 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;
  }```