Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPreResponse not called when error returned/rethrown from failAction of error resp validation #3821

dwelle opened this issue Sep 7, 2018 · 2 comments
bug Bug or defect


Copy link

dwelle commented Sep 7, 2018

Is this a security related issue?


What are you trying to achieve or the steps to reproduce?

Throwing/returning error from failAction handler of response validation (at (2)) skips onPreResponse ext point.

When failAction is not specified at all, onPreResponse is also skipped.

I Assume that's a bug since nothing like that is noted in docs, quite the contrary:


  • always called, unless the request is aborted.

In the code below I'm also checking if the request wasn't aborted which is the only case where onPreResponse shouldn't be called.

(async function () {
    const Hapi = require(`hapi`);
    const Boom = require(`boom`);
    try {
        const server = Hapi.server({
            host: `localhost`,
            port: 3000,
            routes: { cors: true }

            path: `/test`,
            method: `GET`,
            options: {
                response: {
                    status: {
                        500 () {
                            throw new Error(`error didn't pass validation`);
                    failAction () {
                        // throw notFound to see if server correctly responds
                        //  with different error than the originally thrown
                        throw Boom.notFound();
            handler () {

                throw new Boom(`testing`);

        server.ext(`onRequest`, (request, h) => {
  `disconnect`, () => {
                console.error(`request aborted`); // not called
            return h.continue;

        server.ext(`onPreResponse`, (request, h) => {
            console.log(`(3)`); // not called
            return h.continue;
       `request`, (request, event) => {
            console.log(event.tags.includes(`abort`)); // false

        await server.start();
        console.log(`Server started on ${}`);
    } catch ( err ) {

The above is throwing an error, but also happens when returning an error:

failAction ( request, h, error ) {
    return error;

What was the result you received?

onPreResponse ext not called.

What did you expect?

onPreResponse to be called.


  • node version: 10.0.0
  • hapi version: 17.5.4
  • os: Windows 7

EDIT: in fact happens even if error simply returned, not only when error is thrown.
EDIT2: happens also if failAction not specified

@dwelle dwelle changed the title onPreResponse not called when error thrown in failAction of error resp validation onPreResponse not called when error returned/rethrown from failAction of error resp validation Sep 7, 2018
@hueniverse hueniverse self-assigned this Sep 22, 2018
@hueniverse hueniverse added the bug Bug or defect label Sep 22, 2018
@hueniverse hueniverse added this to the 17.5.5 milestone Sep 22, 2018
Copy link

Oh, I had this issue before, ty for fixing it!

Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
bug Bug or defect
None yet

No branches or pull requests

3 participants