mpetazzoni/sse.js

Any way to catch HTTP error status code?

Closed this issue · 1 comments

When there is a server-side error, it would be nice if there would be a way to catch the HTTP error code thrown.

Currently I can catch the error via an event listener like the following, but can't tell the HTTP status code (like 500 or 401, etc):
addEventListener("error", function(e) {

Hi @zoltan-fedor,

This can already be achieved. As noted in the README file, all the events set the event's source to the SSE object itself, so you should be able access the XMLHttpRequest object and its status:

addEventListener('error', function(e) {
  console.log('Request failed, HTTP status was: ' + e.source.xhr.status);
});