adamu
Handling custom errors in Phoenix error view
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?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









