现在对模型抛出错误json的验证如下:
code: "E_INVALID_NEW_RECORD"
details: "Missing value for required attribute `name`. Expected a string, but instead, got: undefined"
message: "The server could not fulfill this request (`POST /api/users`) due to a problem with the parameters that were sent. See the `details` for more info. **The following additional tip will not be shown in production**: Tip: Check your client-side code to make sure that the request data it sends matches the expectations of the corresponding attribues in your model. Also check that your client-side code sends data for every required attribute."
很糟糕,有一些原因:
有没有办法将错误响应作为下面的对象返回?
details: {
name: "Message",
anotherFieldName: "Another message"
}
UPD:模型示例:
/**
* User.js
*
* @description :: A model definition. Represents a database table/collection/etc.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
module.exports = {
attributes: {
name: {
type: 'string',
required: true,
minLength: 10
},
lastName: {
type: 'string',
required: true,
minLength: 10
},
username: {
type: 'string',
required: true
},
anotherFieldName: {
type: 'string',
required: true
}
},
};