捕获hapi请求生命周期中的所有错误。 我有一个注册的处理程序,在HAPI中处理错误
public signup(request: Hapi.Request, reply: Hapi.Base_Reply) {
this.database.user.create(request.payload).then((user: any) => {
return reply({
"success": true
});
}).catch((err) => {
reply(Boom.conflict('User with the given details already exists'));
});
}
现在,我赶上了错误,但我不能总是相信,我将只收到此错误信息。如果数据库中有错误怎么办? 如何为所有请求捕获此类数据库错误或任何其他未知错误。 ???
如果你只是想记录错误,你可以使用'hapi-good'模块https://github.com/hapijs/good – ivo