mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 20:37:59 +01:00
24 lines
565 B
Elixir
24 lines
565 B
Elixir
defmodule PhilomenaWeb.NotFoundPlug do
|
|
alias Phoenix.Controller
|
|
alias Plug.Conn
|
|
|
|
def init([]), do: []
|
|
|
|
def call(conn), do: call(conn, nil)
|
|
|
|
def call(conn, _opts) do
|
|
case conn.assigns.ajax? do
|
|
true ->
|
|
conn
|
|
|> Conn.resp(:not_found, "Couldn't find what you were looking for!")
|
|
|> Conn.halt()
|
|
|
|
false ->
|
|
conn
|
|
|> Controller.fetch_flash()
|
|
|> Controller.put_flash(:warning, "Couldn't find what you were looking for!")
|
|
|> Controller.redirect(to: "/")
|
|
|> Conn.halt()
|
|
end
|
|
end
|
|
end
|