Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sobolevn/0b3e07dbd717f900621a5b78c67f9b84 to your computer and use it in GitHub Desktop.
Save sobolevn/0b3e07dbd717f900621a5b78c67f9b84 to your computer and use it in GitHub Desktop.
defmodule MediumPhxExample.Web.FallbackController do
@moduledoc """
Translates controller action results into valid `Plug.Conn` responses.
See `Phoenix.Controller.action_fallback/1` for more details.
"""
use MediumPhxExample.Web, :controller
def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
conn
|> put_status(:unprocessable_entity)
|> render(MediumPhxExample.Web.ChangesetView, "error.json", changeset: changeset)
end
def call(conn, {:error, :not_found}) do
conn
|> put_status(:not_found)
|> render(MediumPhxExample.Web.ErrorView, :"404")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment