捕獲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