From 90e0bb7ee9e6289e7415038de0994238e611bb3f Mon Sep 17 00:00:00 2001 From: faton Date: Fri, 10 Jul 2020 20:29:35 +0300 Subject: [PATCH] Add support of connection error event --- EventSource.js | 5 +++++ README.md | 6 ++++++ 2 files changed, 11 insertions(+) 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();