add custom error pages

This commit is contained in:
shibao 2022-02-08 22:56:57 -05:00
parent 455fe354c1
commit 8eb956d520
4 changed files with 69 additions and 12 deletions

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en" class="m-0 p-0 w-full h-full">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
<%= dgettext("errors", "Error") %> | Cannery
</title>
<link rel="stylesheet" href="/css/app.css" />
<script defer type="text/javascript" src="/js/app.js">
</script>
</head>
<body class="pb-8 m-0 p-0 w-full h-full">
<header>
<CanneryWeb.Component.Topbar.topbar current_user={assigns[:current_user]}></CanneryWeb.Component.Topbar.topbar>
</header>
<div class="pb-8 w-full flex flex-col justify-center items-center text-center">
<div class="p-8 sm:p-16 w-full flex flex-col justify-center items-center space-y-4 max-w-3xl">
<h1 class="title text-primary-500 text-3xl">
<%= @error_string %>
</h1>
<hr class="w-full hr">
<a href={Routes.live_path(Endpoint, HomeLive)} class="link title text-primary-500 text-lg">
<%= dgettext("errors", "Go back home") %>
</a>
</div>
</div>
</body>
</html>

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en" class="m-0 p-0 w-full h-full">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
@ -15,7 +15,7 @@
> >
</script> </script>
</head> </head>
<body class="m-0 p-0 min-w-full min-h-full"> <body class="m-0 p-0 w-full h-full">
<%= @inner_content %> <%= @inner_content %>
</body> </body>
</html> </html>

View File

@ -1,16 +1,15 @@
defmodule CanneryWeb.ErrorView do defmodule CanneryWeb.ErrorView do
use CanneryWeb, :view use CanneryWeb, :view
alias CanneryWeb.{Endpoint, HomeLive}
# If you want to customize a particular status code def template_not_found(error_path, _assigns) do
# for a certain format, you may uncomment below. error_string =
# def render("500.html", _assigns) do case error_path do
# "Internal Server Error" "404.html" -> dgettext("errors", "Not found")
# end "401.html" -> dgettext("errors", "Unauthorized")
_ -> dgettext("errors", "Internal Server Error")
end
# By default, Phoenix returns the status message from render("error.html", %{error_string: error_string})
# 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 end
end end

View File

@ -119,3 +119,28 @@ msgstr ""
#: lib/cannery/accounts/user.ex:82 #: lib/cannery/accounts/user.ex:82
msgid "must have the @ sign and no spaces" msgid "must have the @ sign and no spaces"
msgstr "" msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/templates/error/error.html.heex:8
msgid "Error"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/views/error_view.ex:10
msgid "Internal Server Error"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/views/error_view.ex:8
msgid "Not found"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/views/error_view.ex:9
msgid "Unauthorized"
msgstr ""
#, elixir-format, ex-autogen
#: lib/cannery_web/templates/error/error.html.heex:25
msgid "Go back home"
msgstr ""