Hello everyone!
I’m trying to improve one of our tooling for handling resource access with Plug and Phoenix LiveView.
What it does basically, is fetching a resource, and if an error occurs (if it cannot be found for example), it halts the Plug conn or LiveView socket, and responds with the status code corresponding to the error.
This works well for a Plug conn, and acceptably for LiveViews mounted in the router (we just redirect to a /not_found
route). However, I could not figure out how to halt a child LiveView, so I decided to make the LiveView crash in this case. This is annoying as it spams our monitoring system quite a lot - for false positives.
The issue is that, when halting a socket in an on_mount
hook, it needs to be redirected (or at least, that’s what the error message says), and trying to redirect from a child LiveView is not possible. We’ve got kind of an impossible situation here
So, is there a way to properly halt a child LiveView? Either by redirecting the user, or by displaying an error message in place of the errored LiveView.
Thanks in advance for your time, have a nice day