Skip to content

Commit

Permalink
Test that logged simple handler errors has a stack
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil authored and Marsup committed Oct 24, 2024
1 parent 909f9bb commit dbbee2c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ describe('handler', () => {
expect(event.error.isBoom).to.equal(true);
expect(event.error.output.statusCode).to.equal(403);
expect(event.error.message).to.equal('Forbidden');
expect(event.error.stack).to.exist();
});
});

Expand Down
36 changes: 36 additions & 0 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,42 @@ describe('Request', () => {
const res = await server.inject('/');
expect(res.statusCode).to.equal(500);
});

it('logs thrown errors as boom errors', async () => {

const server = Hapi.server({ debug: false });
server.route({
method: 'GET',
path: '/',
options: {
handler: function () {

// eslint-disable-next-line no-undef
NOT_DEFINED_VAR;
}
}
});

const log = new Promise((resolve) => {

server.events.on({ name: 'request', channels: 'internal' }, (request, event, tags) => {

if (tags.handler &&
tags.error) {

resolve({ event, tags });
}
});
});

const res = await server.inject('/');
expect(res.statusCode).to.equal(500);

const { event } = await log;
expect(event.error.isBoom).to.equal(true);
expect(event.error.output.statusCode).to.equal(500);
expect(event.error.stack).to.exist();
});
});

describe('_postCycle()', () => {
Expand Down

0 comments on commit dbbee2c

Please sign in to comment.