我们正在使用 Hapi 构建一个 Web 服务。我们的路线有一些验证。我想知道是否可以在 hapi 回复客户端之前或之后捕获或覆盖验证失败时的默认回调。
我的(非工作)代码:
{
method: 'GET',
config: {
tags: tags,
validate: {
params: {
id: Joi.number()
.required()
.description('id of object you want to get'),
},
//Tried this, and it's not working:
callback: function(err, value) {
if (err) {
console.log('need to catch errors here!');
}
}
}
},
path: '/model/{id?}',
handler: function(request, reply) {
reply('Ok');
}
}