logoalt Hacker News

yellow_leadlast Thursday at 6:25 PM2 repliesview on HN

How do you handle HTTP errors?

Just curious because when I used HTMX I didn't enjoy this part.


Replies

wvbdmplast Thursday at 11:32 PM

I like to return errors as text/plain and I have a global event handler for failed requests that throws up a dialog element. That takes care of most things.

Where appropriate, I use an extension that introduces hx-target-error and hx-swap-error, so I can put the message into an element. You can even use the CSS :empty selector to animate the error message as it appears and disappears.

Usually the default behavior, keeping the form as-is, is what you want, so users don’t lose their input and can just retry.

adamzwassermanlast Thursday at 7:02 PM

Honestly? I never think about it. I've never had to. What did you run into? Curious what the pain point was.

show 1 reply