SSE client onException handler doesn't get called when there's an error reconnecting

I started doing some debugging to nail down a situation that causes our users to stop receiving server sent events after they have the browser open for a long time. I was able to fix the issue but I noticed that the onException handler in the ServerEventsClient was not being called after the client was initially disconnected for some reason, like when the user’s computer goes to sleep, wakes back up, and then tries to reconnect again after their session needs to be refreshed. I think I may have narrowed it down to this line of code in the client itself.

index.ts, line 386

const es = this.EventSource
            ? new this.EventSource(url, this.getEventSourceOptions())
            : new EventSource(url, this.getEventSourceOptions());
        es.addEventListener('error', e => opt.onerror || hold.onerror || this.onError);
        es.addEventListener('message', opt.onmessage || hold.onmessage || this.onMessage);

I think the error handler is being set to a function that returns the callback that is supposed to be called instead of the callback itself. Shouldn’t the handler be attached the same way it is for the message event? Should I put up a PR for this kind of thing?



1 Like

Yeah it’s different to get around a TypeScript error which prevented it from being called like the message event handler which needed to be called with a lambda so it compiles, but it needs to also invoke the errorHandler with the lambda argument which is done in this commit.

This change is available from v1.0.30 that’s now available on npm.

Thx for the pointer!

1 Like