htmx icon indicating copy to clipboard operation
htmx copied to clipboard

EventSource: Better error handling of broken connections

Open benpate opened this issue 3 years ago • 3 comments
trafficstars

If a malformed URL (such as https://localhost:99999999999/) is passed to the SSE extension, this would previously cause the extension to throw an exception and break entirely and log a difficult-to-understand error message.

This update adds error checks around this part of the process, and tries to throw a reasonable error, along with triggering standard htmx error events.

There is a new test in the realtime server to demonstrate this process.

benpate avatar Feb 24 '22 17:02 benpate

@1cg - can you review this before we merge? I'm getting different results when I use api.triggerErrorEvent(), depending on when it's being used.

For regular connection errors (like an HTTP 404) the event is triggering just fine. The realtime server demonstrates this well.

But, when this function is called inside a catch statement (i.e. when I have a malformed URL) I can see the error event getting triggered, but it does not propagate to the DOM nodes above. To see this working, change the connection URL on the error page to http://localhost:999999999 (which is not a valid port number) and you'll see what I mean.

benpate avatar Feb 24 '22 17:02 benpate

Hmm. The only way I can see that happening is if the elt is not in the hierarchy or bubbling is being cancelled for some reason.

It all ends up going through makeEvent() which creates events that bubble...

Cheers, Carson

1cg avatar Apr 08 '22 19:04 1cg

Hmm. The only way I can see that happening is if the elt is not in the hierarchy or bubbling is being cancelled for some reason.

It all ends up going through makeEvent() which creates events that bubble...

Cheers, Carson

1cg avatar Apr 08 '22 19:04 1cg

@benpate is this still an issue and do you want to update it and try to get it merged?

alexpetros avatar Jul 30 '23 17:07 alexpetros

Eh, not really. It was just trying to close up a weird corner case that we found because of some other bug. Honestly, if you're connecting to port 99999999999, you kinda deserve what you get :)

But since plenty of other things have moved forward since then, it's probably just best to close this one out. Yes?

benpate avatar Aug 24 '23 00:08 benpate