Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 338 forks source link

How to suppress reconnection error? #194

Open roman-sereda-lohika opened 2 years ago

roman-sereda-lohika commented 2 years ago

Error in my chrome console: Error: No activity within 45000 milliseconds. 11 chars received. Reconnecting.

I am fine that Event Source reconnects from time to time, but don't want to have errors in my console about it.

First of all why this is an error, not a warning? Second is why do you use console.error instead of simply throwing errors?

The second part makes it pretty hard to catch this error, the only way i find to do this is overwriting console.error but it doesn't look like a proper solution, any other ways to suppress error?

Yaffle commented 2 years ago

Can you prevent the error logging for narive EventSource?

roman-sereda-lohika commented 2 years ago

Can you prevent the error logging for narive EventSource?

I am not familiar with native EventSource, but if here we have the same behaviour as in native then i see your point. Just wondering there should be a lot of people who should find this error irritating and how they deal with it

roman-sereda-lohika commented 2 years ago

if i am not mistaken, in 1.0.15 package was just throwing error and it was working fine and i don't see any advantages in using console.error there

Yaffle commented 2 years ago

@roman-sereda-lohika why was it working fine? I think, before some version, the error was not thrown or reported for this case. in other place of the code I was using setTimeout to throw an error, you cannot catch such errors with try-catch and the stack is lost sometimes

Yaffle commented 2 years ago

if you want to ignore the errors, some mechanism is needed. I can think of an 1) extra option or 2) event.preventDefault(); and checking if preventDefault was called in the code before calling console.error() But it is hard to make a decision as this is not part of the native EventSource and I have not seen a lot someone doing this.

roman-sereda-lohika commented 2 years ago

@Yaffle ahh, sorry for confusing, yeah, i see that it was not reported at all in previous versions, well, ok, i will just use some hacks around console.error, but if somebody else will argue about this i hope that some mechanism will be created, thanks

monstrum commented 2 years ago

I don't know, what you are using. In the Mercure Rocks, you can passed the Heart Beat Interval. Just set this lower than 45 Seconds, you should good to go. and if you can change the interval, then you can increase the interval in the event source options heartbeatTimeout.

udhayakumarcp commented 2 years ago

I am too facing the same error

edarioq commented 2 years ago

Solved it by

const eventSource = new EventSourcePolyfill('api/incoming', { heartbeatTimeout: 100000000 })

olinox14 commented 2 years ago

It would be a useful feature to allow to disable the heartbeat. Mercure allows to do so in the hub config : https://mercure.rocks/docs/hub/config So if you can disable it in the hub, being able to do the same client-side seems coherent.

botjaeger commented 2 years ago

solved it by adding this to my Mercure config heartbeat 15s

onderilkesever commented 11 months ago

It would be nice to have one of the two options you listed

https://github.com/Yaffle/EventSource/issues/194#issuecomment-934469139