Skip to content

Do not abort the connection on authentication errors #20

@PapaNappa

Description

@PapaNappa

At line 218 of eventsource.js you check for error code ≥ 500 and retry the connection:

if (xhr.status >= 500) {

Errors in the 400 range, on the other hand, will lead to an abort:

EventSource/eventsource.js

Lines 306 to 318 in 1859fa4

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?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions