diff --git a/EventSource.js b/EventSource.js index e160834..c58a7be 100644 --- a/EventSource.js +++ b/EventSource.js @@ -118,6 +118,11 @@ var EventSource = function(url, options) { } else if (eventsource.readyState !== eventsource.CLOSED) { if (this.readyState == 4) { // and some other status + eventsource.dispatchEvent('connection-error', { + type: 'connection-error', + status: this.status, + message: this.responseText, + }); pollAgain(interval); } else if (this.readyState == 0) { // likely aborted diff --git a/README.md b/README.md index c8708af..59ed3cb 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ class MyApp extends Component { console.log(data.type); // message console.log(data.data); }); + + // Grab connection error events with the type of 'connection-error' + this.eventSource.addEventListener('connection-error', (data) => { + console.log(data.message); // message + console.log(data.status); // http status code + }); } componentWillUnmount() { this.eventSource.removeAllListeners();