philomena/lib/philomena_web/views/error_view.ex

44 lines
1.2 KiB
Elixir
Raw Permalink Normal View History

2019-08-15 02:32:32 +02:00
defmodule PhilomenaWeb.ErrorView do
use PhilomenaWeb, :view
2021-09-19 23:22:48 +02:00
import PhilomenaWeb.LayoutView,
only: [
2024-04-28 05:01:16 +02:00
stylesheet_path: 1,
dark_stylesheet_path: 0,
2021-09-19 23:22:48 +02:00
viewport_meta_tag: 1
]
2021-08-21 03:07:48 +02:00
@codes %{
400 => {"Bad Request", "Couldn't process your request!"},
403 => {"Forbidden", "Not allowed to access this page (are your cookies enabled?)"},
404 => {"Not Found", "Couldn't find what you were looking for!"},
2021-09-19 23:22:48 +02:00
500 => {"Internal Error", "Couldn't process your request!"}
2021-08-21 03:07:48 +02:00
}
2019-08-15 02:32:32 +02:00
# By default, Phoenix returns the status message from
# the template name. For example, "404.html" becomes
# "Not Found".
def template_not_found(template, _assigns) do
Phoenix.Controller.status_message_from_template(template)
end
2021-08-21 03:07:48 +02:00
def render(template, assigns) when template != "show.html" do
{short_msg, long_msg} = @codes[assigns.status] || @codes[500]
2021-09-28 01:18:14 +02:00
case Phoenix.Controller.get_format(assigns.conn) do
"json" ->
%{"error" => short_msg}
_ ->
render(
PhilomenaWeb.ErrorView,
"show.html",
conn: assigns.conn,
status: assigns.status,
short_msg: short_msg,
long_msg: long_msg
)
end
2021-08-21 03:07:48 +02:00
end
2019-08-15 02:32:32 +02:00
end