Merge branch 'feature/improve-error-logging' into 'develop'
logging: improve visibility into ISE errors See merge request pleroma/pleroma!845
This commit is contained in:
commit
1f85c9c9c7
|
@ -4,14 +4,21 @@
|
||||||
|
|
||||||
defmodule Pleroma.Web.ErrorView do
|
defmodule Pleroma.Web.ErrorView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
|
require Logger
|
||||||
|
|
||||||
def render("404.json", _assigns) do
|
def render("404.json", _assigns) do
|
||||||
%{errors: %{detail: "Page not found"}}
|
%{errors: %{detail: "Page not found"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("500.json", _assigns) do
|
def render("500.json", assigns) do
|
||||||
|
Logger.error("Internal server error: #{inspect(assigns[:reason])}")
|
||||||
|
|
||||||
|
if Mix.env() != :prod do
|
||||||
|
%{errors: %{detail: "Internal server error", reason: inspect(assigns[:reason])}}
|
||||||
|
else
|
||||||
%{errors: %{detail: "Internal server error"}}
|
%{errors: %{detail: "Internal server error"}}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# In case no render clause matches or no
|
# In case no render clause matches or no
|
||||||
# template is found, let's render it as 500
|
# template is found, let's render it as 500
|
||||||
|
|
|
@ -14,11 +14,16 @@ test "renders 404.json" do
|
||||||
|
|
||||||
test "render 500.json" do
|
test "render 500.json" do
|
||||||
assert render(Pleroma.Web.ErrorView, "500.json", []) ==
|
assert render(Pleroma.Web.ErrorView, "500.json", []) ==
|
||||||
%{errors: %{detail: "Internal server error"}}
|
%{errors: %{detail: "Internal server error", reason: "nil"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "render any other" do
|
test "render any other" do
|
||||||
assert render(Pleroma.Web.ErrorView, "505.json", []) ==
|
assert render(Pleroma.Web.ErrorView, "505.json", []) ==
|
||||||
%{errors: %{detail: "Internal server error"}}
|
%{errors: %{detail: "Internal server error", reason: "nil"}}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "render 500.json with reason" do
|
||||||
|
assert render(Pleroma.Web.ErrorView, "500.json", reason: "test reason") ==
|
||||||
|
%{errors: %{detail: "Internal server error", reason: "\"test reason\""}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue