I'm trying to get information about an error when using EventSource in NodeJs, I think you could understand me better with the following example:
var url = 'http://api.example.com/resource'
var EventSource = require('eventsource');
var es = new EventSource(url);
es.onmessage = function(e) {
console.log(e.data);
};
es.onerror = function(event) {
console.log(event);
};
In the onerror function I would like to get information about the error but the event
is empty or undefined as well as the es
object (well, this object just cames with a pair of curly brackets {}
). I would like to read the response header in case of error, something like:
es.onerror = function(e) {
console.log(e.header.location);
};
Is this possible? What I'm missing? I think the answer should be very easy but I'm a king of new in NodeJs.
Eventsource
? – HaerleEventSource
when I create a new instance and then I'm subscribing me to the eventonmessage
andonerror
. – Uchida