At line 218 of eventsource.js you check for error code ≥ 500 and retry the connection:
Errors in the 400 range, on the other hand, will lead to an abort:
|
if (status !== 0 && (status !== 200 || contentType !== "")) { |
|
var message = ""; |
|
if (status !== 200) { |
|
message = "EventSource's response has a status " + status + " " + statusText.replace(/\s+/g, " ") + " that is not 200. Aborting the connection."; |
|
} else { |
|
message = "EventSource's response has a Content-Type specifying an unsupported type: " + contentType.replace(/\s+/g, " ") + ". Aborting the connection."; |
|
} |
|
setTimeout(function () { |
|
var ev = new Event("error", status, message); |
|
fire(that, that.onerror, ev); |
|
throw new Error(message); |
|
}, 0); |
|
isWrongStatusCodeOrContentType = true; |
Retrying the connection on errors that are not internal server errors would favor our use case (where we update authentication headers when they become invalid).
I see two possible options: always retry on errors ≥ 400 (instead of 500), or add a return value to the onError callback and retry if the error handler allows this (this is probably over-engineering?).
At line 218 of eventsource.js you check for error code ≥ 500 and retry the connection:
EventSource/eventsource.js
Line 218 in 1859fa4
Errors in the 400 range, on the other hand, will lead to an abort:
EventSource/eventsource.js
Lines 306 to 318 in 1859fa4
Retrying the connection on errors that are not internal server errors would favor our use case (where we update authentication headers when they become invalid).
I see two possible options: always retry on errors ≥ 400 (instead of 500), or add a return value to the onError callback and retry if the error handler allows this (this is probably over-engineering?).