Hacker News new | past | comments | ask | show | jobs | submit login

Well, we could go back to the original model for the web, using REST & HATEOAS without arguing or even really thinking about it, by building hypertext-based applications.

Of course, the hypertext we have, HTML, wasn't completed, and it leaves a lot to be desired. I have tried to fix that with htmx:

https://htmx.org




Hey, this is super cool. Thanks for building it!

One quick question: How should I be handling server side errors with this? Like, normally I’d check the status code coming from the server and throw up an error modal if it’s an error - what’s the equivalent mechanism here?


htmx triggers a bunch of different events based on various request life cycle events.

For server errors you'd use htmx:responseError:

https://htmx.org/events/#htmx:responseError

You could write some code like so:

   htmx.on("htmx:responseError", function(evt) {
     GrowlNotification.notify({
       title: 'Request Error',
       description: evt.detail.xhr.responseText
     })
   })
And that would show a growl notification in the event of an request error. Or however you wanted to display it.


I haven't looked into htmx much yet, but am using its predecessor intercooler-js, and this is my code for handling server responses and displaying an error message when it's needed: https://gitlab.com/tildes/tildes/-/blob/master/tildes/static...

I wouldn't consider it particularly elegant, but it's straightforward and has worked well. It uses the "complete.ic" event to trigger whenever an intercooler request finishes, and then uses the response status/code/text to display an appropriate message.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: