2

I'm thinking through how Turbo Streams work, mostly as a thought experiment. I understand the basics after building a simple toy application. It's pretty powerful that so much can be done with a handful of Turbo Frames.

It's interesting to be able to respond with a Turbo Frame and the right content is replaced in the DOM. However, I've noticed that if a link within a Turbo Frame responds with HTTP 404, it only shows up in the error console. (Nothing changes on the visible page.) What's the best practice for handling errors like these? What's a simple option to give the user an indication that there's a broken link?

Benjamin Oakes
  • 12,262
  • 12
  • 65
  • 83

1 Answers1

0

You could do a rescue_from method in the controller that catches that specific error then use turbo_streams to update the page with a nice little error message

yungindigo
  • 241
  • 1
  • 6
  • I don't think that's a very good solution because turbo streams are only supported on form submissions and subscribing to updates. – Benjamin Oakes Feb 23 '22 at 15:28
  • @BenjaminOakes this is incorrect. You can add turbo streams to literally any controller action / server response, not constrained to a form submission or model update. – aidan May 22 '22 at 06:03
  • Hmm, maybe a difference in how I'm using the terminology. In any case, can you please educate me on how that would best be used for a 404 response? An example would be very helpful. – Benjamin Oakes May 23 '22 at 10:44