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

Throwing in handler crashes the server, but not in all cases #3203

Closed
matthieusieben opened this issue Jun 13, 2016 · 2 comments
Closed

Throwing in handler crashes the server, but not in all cases #3203

matthieusieben opened this issue Jun 13, 2016 · 2 comments
Assignees
Labels
bug Bug or defect

Comments

@matthieusieben
Copy link

If you have a route, that has a pre handler that returns a native Node promise and if an Exception is thrown from the main handler, the server crashes:

const Hapi = require('hapi');

var server = new Hapi.Server();

server.connection({
    port: 3000
});


server.method('promiseMethod', () => Promise.resolve('result'), { callback: false })
server.method('callbackMethod', (next) => next('result'))

server.route({
    method: 'GET',
    path: '/willCrash',
    config: {
        pre: [
            { method: 'promiseMethod()' },
        ]
    },
    handler: function(request, reply){
        throw new Error('Oops');
    }
});
server.route({
    method: 'GET',
    path: '/wontCrash',
    config: {
        pre: [
            { method: 'callbackMethod()' },
        ]
    },
    handler: function(request, reply){
        throw new Error('Oops');
    }
});

server.start(() => {
    console.log('Server listening ...')
})

The server will crash when a GET request is made on /willCrash but not on /wontCrash. Note that it is not the case when Bluebird promises are used instead.

This issue can be fixed using #3196, even though the right solution might be more profound.

@Marsup
Copy link
Contributor

Marsup commented Jun 13, 2016

Already fixed by #3202.

@Marsup Marsup added the bug Bug or defect label Jun 13, 2016
@Marsup Marsup self-assigned this Jun 13, 2016
@rmedaer
Copy link

rmedaer commented Jun 15, 2016

It seems that this is the same issue than here : #3196

To be confirmed...

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

No branches or pull requests

4 participants