Rakakku

Rakakku

How to render an ErrorView, without FallbackController?

Trying to render an error view:

 # in a controller

  def test1(conn, params) do
    case Repo.get_by(MyModel, title: params["title"]) do
      nil ->
        put_status(conn, 403)
        |> put_layout(false)
        |> render(MyAppWeb.ErrorView, "404.html")


# in the config:

debug_errors: false,

Output:

Internal server error

Why? No idea.

And a 2nd question: How can render an error html template with no layout without having to say put_layout(false) from a controller? Namely, I want to set “nil” layout from within ErrorView.

Most Liked

kokolegorille

kokolegorille

You can build your own render error function if You want to dry your code.

def test1(conn, params) do
    case Repo.get_by(MyModel, title: params["title"]) do
      nil -> render_error(conn)
...

defp render_error(conn) do
  conn
  |> put_status(403)
  |> put_layout(false)
  |> render(MyAppWeb.ErrorView, "404.html")
end
kokolegorille

kokolegorille

No You can’t.

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
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
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement