我正在使用帆(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

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

最佳答案

在响应文件夹中修改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 - 删除帆中的invalidAttributes,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32338283/

10-09 22:09