3
我有一個羽毛球API與messages service
。我想用feathers-hooks-validate-joi
模塊驗證消息模型。Joi驗證feathersjs
這裏是我的messages-hooks.js
文件:
const validate = require('feathers-hooks-validate-joi');
const schema = require('./messages.validator');
module.exports = {
before: {
create: [validate.form(schema)],
//others method fields
},
after: {...},
error: {...}
};
這裏是我的messages.validator.js
文件:
const Joi = require('joi');
const schema = Joi.object().keys({
name: Joi.string().trim().min(2).required(),
text: Joi.string().trim().min(2).required()
});
module.exports = {schema};
當我嘗試通過捲曲發佈一條消息:
curl 'http://localhost:3030/messages/' -H 'Content-Type: application/json' --data-binary '{ "name": "Hello", "text": "World" }'
我收到此錯誤消息:
{
"name": "BadRequest",
"message": "Invalid data",
"code": 400,
"className": "bad-request",
"data": {},
"errors": {
"name": "\"name\" is not allowed",
"text": "\"text\" is not allowed"
}
}
我錯過了什麼嗎?我是否正確使用羽毛鉤?
:'{ 「名」:「GeneralError」, 「消息」:「無法讀取屬性'convert'of undefined「, 」code「:500, 」className「:」general-error「, 」data「:{}, 」errors「:{} } –