我已经为joi验证错误处理创建了一个中间件,但它返回时带有一些警告,比如' error :无法在发送‘后设置标题
错误:
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3)
at ServerResponse.header (D:\nodejs\bigfish\node_modules\express\lib\respo
我有一个带有下拉输入的表单,所以输入的选项已经设置好了。 问题是,尽管输入的值是正确的,而且它在模式的可接受值内,但我得到的消息是Provider must be one of [[object Set], [object Set]]。 最奇怪的是,这个问题在生产中出现了,但在localhost中我没有得到这个验证错误。 来自schema的provider密钥 provider: Joi.string().required().label('Provider').when('entitlementType', {
is: 'Offer'
因此,我试图验证我的帖子请求的数据。为此,我想使用乔依,但似乎有什么东西,我错过了什么地方。
这是我的帖子请求:
app.post('/new-comp', async (req: any, res: any) => {
const validation = schemaComp.validate(req.body)
// need to declare an if/else statement to manage the error
// for now, console.logs the info that data is not valid
cons