fknop/hapi-pagination

Undefine request.response.source issue

garbles9100 opened this issue · 3 comments

I found an issue where if an error occurs before a response is generated then things aren't handled correctly in ext.js. For example, if a database exception occurs in the handler before reply.paginate is called then another exception occurs on line 149 of ext.js because it is trying to read a property on an undefined object. A simple fix for this is to check the source for being undefined prior to line 149.

I believe this is a side effect of the reply function being a shortcut for reply.paginate. Unless I am mistaken, when this code catches the initial exception
.catch((err) => {
server.log(['ERROR'], err.message);
reply(err);
});
the pagination code is still executed even though my actual call to reply.paginate is never called.

I verified that this is only an issue because of moving the onPreResponse logic to onPostHandler.

fknop commented

I'll do that in the morning. (Midnight here)

No worries. Thanks!