I’m experimenting with handling custom errors in Phoenix.
I’ve defined a custom error, MyApp.NotFoundError
which implements Plug.Exception
to return :not_found
.
I’ve also defined an error_html/404.heex
component that will render a 404 page when this error (amongst others) is raised.
What I’m struggling with is how to add context-specific information to this error page. For example, debugging the assigns
passed to the component, I can see that a map with reason
(containing my raised error), status
, stack
, kind: :error
, etc. is passed to the component, but I can’t see any documentation about these variables - the docs only refer to assigns that are passed in from the controller (of which there is none, in this case, because Phoenix is directly rendering the error view), and I don’t want to depend on observed behaviour.
What I want to do, for example, is have the 404 page say something more specific than just “Not Found” if I can provide extra information because I know I have a MyApp.NotFoundError
.
Does it make sense to detect the reason
from the view? Is that documented anywhere? Or is there a better approach to adding context to custom errors?