Implementing action fallback
Phoenix supports using a plug as a fallback to any controller action. This plug can be used to translate data returned by a controller action that is not a %Plug.Conn{} struct into a %Plug.Conn{} struct. The fallback plug is registered by calling the Phoenix.Controller.action_fallback/1 macro.
The following is a controller that uses action_fallback:
defmodule ExampleWeb.PageController do
use Phoenix.Controller
action_fallback ExampleWeb.FallbackController
def index(conn, params) do
case list_pages(params) do
{:ok, pages} -> render(conn, "index.html",
pages: pages)
other -> other # includes {:error, :bad_params}
&...