Node.js hapi error after upgrading: TypeError: Uncaught error: Object [object Object] has no method 'reply'

StackOverflow https://stackoverflow.com/questions/21523523

Domanda

We have developed our services using hapi framework in node.js. Recently we found out that there is new version of hapi available for installing via npm install. So we upgraded from 1.20 to 2.1.2. now for every http request that I send to the server I get this error message:

Debug: hapi, internal, implementation, error 
TypeError: Uncaught error: Object [object Object] has no method 'reply'

I used to get this message when, as a result of a bug in my code, the service was trying to reply to a request more than once. Apparently, in the second try the reply function of the request object would be missing. But now after upgrading to newer version of hapi, it seems that the problem should be something that I don't understand.

È stato utile?

Soluzione

Since Hapi 2.0, the way you handle a route has changed a bit. Now, you have to grab a reply from the parameters in your function:

server.route({
    method: 'GET',
    path: '/hello',
    handler: function (request, reply) {

        reply('hello world');
    }
});

I think it was already possible before but it wasn't mandatory.

More informations: https://github.com/spumko/hapi/blob/master/docs/Reference.md#reply-interface

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top