2019-12-02 03:30:58 +01:00
|
|
|
defmodule PhilomenaWeb.NotFoundPlug do
|
|
|
|
alias Phoenix.Controller
|
|
|
|
alias Plug.Conn
|
|
|
|
|
|
|
|
def init([]), do: []
|
|
|
|
|
|
|
|
def call(conn), do: call(conn, nil)
|
2020-01-11 05:20:19 +01:00
|
|
|
|
2019-12-02 03:30:58 +01:00
|
|
|
def call(conn, _opts) do
|
2020-09-28 05:53:14 +02:00
|
|
|
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(:error, "Couldn't find what you were looking for!")
|
|
|
|
|> Controller.redirect(to: "/")
|
|
|
|
|> Conn.halt()
|
|
|
|
end
|
2019-12-02 03:30:58 +01:00
|
|
|
end
|
2019-12-15 04:25:11 +01:00
|
|
|
end
|