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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
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