N.Nicolas N.Nicolas - 10 months ago 375
Node.js Question

throw new RangeError node js

I'm trying to work with IBM Watson Conversation service with Node.js.
I use 'express' to post a message:

app.post( '/api/message', function(req, res) {

and to print the message got from the service:

conversation.message( payload, function(err, data) {
if ( err ) {
return res.status( err.code || 500 ).json( err );
return res.json( updateMessage( payload, data ) );
} );

I just ran the application on port 3000. While the page is not loaded and I got this error:

throw new RangeError(`Invalid status code: ${statusCode}`);

RangeError: Invalid status code: 0
at ServerResponse.writeHead (_http_server.js:192:11)
at ServerResponse._implicitHeader (_http_server.js:157:8)
at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10)
at ServerResponse.send (C:\IBM\1.Mission\2016\conversation-simple-master(1)\
at ServerResponse.json (C:\IBM\1.Mission\2016\conversation-simple-master(1)\
at C:\IBM\1.Mission\2016\conversation-simple-master(1)\conversation-simple-m
at Request._callback (C:\IBM\1.Mission\2016\conversation-simple-master(1)\co
at self.callback (C:\IBM\1.Mission\2016\conversation-simple-master(1)\conver
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)

I don't think the problem is from npm, back my package... While it seems a generic problem...Thanks for you help.

qzb qzb

Request to IBM Watson Conversation service probably ended with error with code "0" and it isn't a valid HTTP status code. This should work:

conversation.message(payload, function(err, data) {
  if (err) {
    return res.status(500).json(err);

  return res.json(updateMessage(payload, data));