Enhance error message output in Node.js to close the listener
P粉517475670
P粉517475670 2024-04-03 09:35:52
0
1
502

I have the following code that handles http requests.

request.connection.addListener('close', function(had_error) {
   console.log(had_error);
   ...

I want to print more error information, but it only prints "true".

P粉517475670
P粉517475670

reply all(1)
P粉662614213

Use Error events to track errors. It returns an Error object containing complete details.

request.connection.addListener('error', function(error) {
    console.log(error.reason|| error.message);
});

Since the connection has been deprecated since v15, you can also use it if you are using the latest version

request.on('error',function(error){
    console.log(error.reason|| error.message);
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template