adamu

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?

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement