EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

Do not abort the connection on authentication errors

Open PapaNappa opened this issue 7 years ago • 2 comments

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

https://github.com/sguiheux/EventSource/blob/1859fa4ccb8c16e07b09dc458e035ca68e18b8b7/eventsource.js#L218

Errors in the 400 range, on the other hand, will lead to an abort: https://github.com/sguiheux/EventSource/blob/1859fa4ccb8c16e07b09dc458e035ca68e18b8b7/eventsource.js#L306-L318

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

PapaNappa avatar Oct 18 '18 13:10 PapaNappa

It's normal to retry on error >= 500 because it's a server error, so we retry until it works With error < 500, the problem come from the client, so you can retry any time it will not work (404 will be alway 404), so no retry on error < 500.

If your problem is about loosing lastEventID maybe we can add it on onErrorEvent and accept it on EventSource constructor or update function

sguiheux avatar Oct 18 '18 13:10 sguiheux

This sounds good to me!

PapaNappa avatar Oct 18 '18 13:10 PapaNappa