And whether (if it does generate the stack trace) this controller would be any faster when lots of requests to non-existent resources are being made
def show(conn, %{"id" => resource_id}) do
case Resource.get(resource_id) do
nil -> render(conn, MyApp.ErrorView, "404.html")
resource -> render(conn, "show.html", resource: resource)
end
end
Finally, I wonder if an authorization library based on exceptions would be much slower than something like https://github.com/schrockwell/bodyguard, because I want to do this
# in controller
def create(conn, %{"resource" => resource_params}, current_user) do
case Resource.create(resource_params, user: current_user) do
{:ok, resource} -> redirect(conn, to: resource_path(conn, :show, resource))
{:error, changeset} -> render(conn, "new.html", changeset: changeset)
end
end
# in resource context
def create(params, user: user) do
# raises an exception that has a Plug.Exception implementation
authorize!(:create, user)
%Resource{owner_id: user.id}
|> Resource.changeset(params)
|> Repo.insert()
end