How to manually/forcefully throw a 404?

I am writing a super simple authorization plug. This plug checks to see if the current user’s role is in the list of approved roles for this scope. if the test passes, I’d like to move on. This part works.

In the case of a failure, I would like to halt and throw a 404.

Can I do this?


conn |> Plug.Conn.put_status(404) |> Plug.Conn.halt

1 Like

Perfect! I had to tell it to render something. This is what I ended up doing, and it works as advertised.

      |> put_status(404)
      |> Phoenix.Controller.render(FulfillmentCartWeb.ErrorView, "404.html")
      |> halt()