diff --git a/lib/kmxgit_web/controllers/error_controller.ex b/lib/kmxgit_web/controllers/error_controller.ex
new file mode 100644
index 0000000..0ec1332
--- /dev/null
+++ b/lib/kmxgit_web/controllers/error_controller.ex
@@ -0,0 +1,13 @@
+defmodule KmxgitWeb.ErrorController do
+ use KmxgitWeb, :controller
+
+ def show(conn, params) do
+ code = params["code"]
+ case code do
+ ["500"] -> raise "Testing error 500 from controller."
+ ["500", "view"] -> render(conn, :"500")
+ ["500", "assign"] -> render(conn, :assign)
+ _ -> not_found(conn)
+ end
+ end
+end
diff --git a/lib/kmxgit_web/router.ex b/lib/kmxgit_web/router.ex
index b03a427..c7f9a51 100644
--- a/lib/kmxgit_web/router.ex
+++ b/lib/kmxgit_web/router.ex
@@ -53,6 +53,10 @@ defmodule KmxgitWeb.Router do
get "/install", PageController, :doc_git_install
end
end
+
+ scope "/_error" do
+ get "/*code", ErrorController, :show
+ end
end
## Authentication routes
@@ -142,20 +146,14 @@ end
get "/password/edit", UserController, :edit_password, as: :""
put "/password", UserController, :update_password, as: :""
end
-
import Phoenix.LiveDashboard.Router
live_dashboard "/dashboard", metrics: KmxgitWeb.Telemetry
end
end
- # Enables the Swoosh mailbox preview in development.
- #
- # Note that preview only shows emails that were sent by the same
- # node running the Phoenix server.
if Mix.env() == :dev do
scope "/_dev" do
pipe_through :browser
-
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
@@ -166,8 +164,12 @@ end
get "/:owner/*slug", RepositoryController, :show
end
- # Other scopes may use custom stacks.
- # scope "/api", KmxgitWeb do
- # pipe_through :api
- # end
+ if Mix.env() != :dev do
+ use Plug.ErrorHandler
+ @impl Plug.ErrorHandler
+ def handle_errors(conn, params) do
+ IO.inspect(params)
+ send_resp(conn, conn.status, "Error ! We have been notified, please retry later.")
+ end
+ end
end
diff --git a/lib/kmxgit_web/templates/error/assign.html.heex b/lib/kmxgit_web/templates/error/assign.html.heex
new file mode 100644
index 0000000..6a0b899
--- /dev/null
+++ b/lib/kmxgit_web/templates/error/assign.html.heex
@@ -0,0 +1 @@
+<%= @azertyuiop %>