Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between request.on('error') and response.on('error')

Tags:

node.js

when making an http.request there are 2 events that produce errors: request.on('error') and response.on('error').

I can't see a difference because both errors come from the web server.

what's the difference between thisError and thatError ?

var request = http.request({hostname:"example.com"}, function(response){
    response.on('error', function(thisError){
     //what's the difference between thisError <<<<<<
    });
});
request.on('error', function(thatError){
    //and thatError      <<<<<
});
like image 999
bubakazouba Avatar asked Dec 28 '15 22:12

bubakazouba


1 Answers

During a request you resolve a name, establish a connection, send a bunch of data, and each task could result in an error.

When you receive data through a response object, as an example the other end could close the connection unexpectedly.

Those errors are different and they must belong to the right structure, in this case respectively request and response.

like image 166
skypjack Avatar answered Sep 30 '22 08:09

skypjack