"Error: socket hung up" using Express

Node keeps going away from me when the client refreshes when the page loads (so the socket ends and I am still processing the request). Error:

[ERROR] - Error: socket hang up
   at createHangUpError (http.js:1472:15)
   at Socket.socketCloseListener (http.js:1522:23)
   at Socket.EventEmitter.emit (events.js:95:17)
   at TCP.close (net.js:465:12) (at lib/Maintenance.js:38)

I tried adding on('error', ...to:

  • req objects
  • Return value listen(I use Express)
  • The return value of the methods get, useand post.

And yet I cannot understand this error; it throws all the same, and none of error handlers reacts. What can I lose?

+4
source share
2 answers

Connect error listeners to socket objects

app.use(function(req, res, next) {
    req.socket.on("error", function() {

    });
    res.socket.on("error", function() {

    });
    next();
});
+8
source

, , , .

app.use(function(err,req, res, next) {
    if(err)console.log(err);
    next();
});
+1

Source: https://habr.com/ru/post/1543534/


All Articles