diff --git a/assets/raw/404_unicorn.png b/assets/raw/404_unicorn.png new file mode 100644 index 0000000..aa41480 Binary files /dev/null and b/assets/raw/404_unicorn.png differ diff --git a/assets/raw/50x_unicorn.png b/assets/raw/50x_unicorn.png new file mode 100644 index 0000000..39baa8e Binary files /dev/null and b/assets/raw/50x_unicorn.png differ diff --git a/assets/static/images/err_view/40x_rainbow.jpg b/assets/static/images/err_view/40x_rainbow.jpg new file mode 100644 index 0000000..4abbd94 Binary files /dev/null and b/assets/static/images/err_view/40x_rainbow.jpg differ diff --git a/assets/static/images/err_view/40x_unicorn-300.png b/assets/static/images/err_view/40x_unicorn-300.png new file mode 100644 index 0000000..39835fb Binary files /dev/null and b/assets/static/images/err_view/40x_unicorn-300.png differ diff --git a/assets/static/images/err_view/50x_rainbow.jpg b/assets/static/images/err_view/50x_rainbow.jpg new file mode 100644 index 0000000..86a69a1 Binary files /dev/null and b/assets/static/images/err_view/50x_rainbow.jpg differ diff --git a/assets/static/images/err_view/50x_unicorn-300.png b/assets/static/images/err_view/50x_unicorn-300.png new file mode 100644 index 0000000..6eab0c0 Binary files /dev/null and b/assets/static/images/err_view/50x_unicorn-300.png differ diff --git a/config/dev.exs b/config/dev.exs index bf56af1..3982878 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -8,7 +8,7 @@ use Mix.Config # with webpack to recompile .js and .css sources. config :home73k, Home73kWeb.Endpoint, http: [port: 4000], - debug_errors: true, + debug_errors: false, code_reloader: true, check_origin: false, watchers: [ diff --git a/lib/home73k_web/controllers/home_controller.ex b/lib/home73k_web/controllers/home_controller.ex index dcd9766..5ca59bf 100644 --- a/lib/home73k_web/controllers/home_controller.ex +++ b/lib/home73k_web/controllers/home_controller.ex @@ -16,4 +16,29 @@ defmodule Home73kWeb.HomeController do def folio(conn, _params) do render(conn, "folio.html", page_title: "Folio") end + + @valid_codes [400..418, 421..426, 428..429, 500..508] + |> Enum.map(&Enum.to_list/1) + |> Enum.concat() + |> Enum.concat([431, 451, 510, 511]) + + def err(conn, params) do + code = Map.get(params, "code", "404") |> err_code_as_int() + code = code in @valid_codes && code || 404 + + conn + |> put_status(code) + |> put_layout(false) + |> put_root_layout(false) + |> put_view(Home73kWeb.ErrorView) + |> render("#{code}.html") + end + + defp err_code_as_int(code) do + try do + String.to_integer(code) + rescue + _ -> 404 + end + end end diff --git a/lib/home73k_web/router.ex b/lib/home73k_web/router.ex index b50998c..c3c2599 100644 --- a/lib/home73k_web/router.ex +++ b/lib/home73k_web/router.ex @@ -28,6 +28,8 @@ defmodule Home73kWeb.Router do get "/about", HomeController, :about get "/resume", HomeController, :resume get "/folio", HomeController, :folio + get "/err", HomeController, :err + get "/err/:code", HomeController, :err # Blog live "/blog", BlogLive, :index diff --git a/lib/home73k_web/templates/error/e40x.html.eex b/lib/home73k_web/templates/error/e40x.html.eex new file mode 100644 index 0000000..4d41a66 --- /dev/null +++ b/lib/home73k_web/templates/error/e40x.html.eex @@ -0,0 +1,59 @@ + + + + + + + <%= @conn.status %> <%= Plug.Conn.Status.reason_phrase(@conn.status) %> \ 73k + + + + + + "> + "> + "> + "> + " color="#78868a"> + + + + + + "/> + + + + + + + +
+ + " class="img-fluid mb-3" alt="UNICORN"> + +

Oh no! Problem!

+

<%= @conn.status %> • <%= Plug.Conn.Status.reason_phrase(@conn.status) %>

+ + <%= link to: Routes.home_path(@conn, :index), class: "border-0 text-light text-center mb-3", title: "Home" do %> +

Click home to get back to safety!

+ <%= icon_div @conn, "mdi-home", [class: "icon"], [ style: "width: 100px; height: 100px;"] %> + <% end %> + +

+ (Unicorn image Creative Commons 4.0 BY-NC + via pngimg.com) +

+ +
+ + + diff --git a/lib/home73k_web/templates/error/e50x.html.eex b/lib/home73k_web/templates/error/e50x.html.eex new file mode 100644 index 0000000..fe660ca --- /dev/null +++ b/lib/home73k_web/templates/error/e50x.html.eex @@ -0,0 +1,59 @@ + + + + + + + <%= @conn.status %> <%= Plug.Conn.Status.reason_phrase(@conn.status) %> \ 73k + + + + + + "> + "> + "> + "> + " color="#78868a"> + + + + + + "/> + + + + + + + +
+ + " class="img-fluid mb-3" alt="UNICORN"> + +

K̷z̴z̶t̸.̶ ̷E̷r̷r̶o̸r̸!̶

+

<%= @conn.status %> • <%= Plug.Conn.Status.reason_phrase(@conn.status) %>

+ + <%= link to: Routes.home_path(@conn, :index), class: "border-0 text-light text-center mb-3", title: "Home" do %> +

Click home to get back to safety!

+ <%= icon_div @conn, "mdi-home", [class: "icon"], [ style: "width: 100px; height: 100px;"] %> + <% end %> + +

+ (Unicorn image Creative Commons 4.0 BY-NC + via pngimg.com) +

+ +
+ + + diff --git a/lib/home73k_web/views/error_view.ex b/lib/home73k_web/views/error_view.ex index ff59705..526542b 100644 --- a/lib/home73k_web/views/error_view.ex +++ b/lib/home73k_web/views/error_view.ex @@ -13,4 +13,7 @@ defmodule Home73kWeb.ErrorView do def template_not_found(template, _assigns) do Phoenix.Controller.status_message_from_template(template) end + + def render("4" <> _rest, assigns), do: render("e40x.html", assigns) + def render("5" <> _rest, assigns), do: render("e50x.html", assigns) end