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:
lambda 2019-02-20 18:21:58 +00:00
commit 1f85c9c9c7
2 changed files with 16 additions and 4 deletions

View file

@ -4,14 +4,21 @@
defmodule Pleroma.Web.ErrorView do
use Pleroma.Web, :view
require Logger
def render("404.json", _assigns) do
%{errors: %{detail: "Page not found"}}
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"}}
end
end
# In case no render clause matches or no
# template is found, let's render it as 500

View file

@ -14,11 +14,16 @@ defmodule Pleroma.Web.ErrorViewTest do
test "render 500.json" do
assert render(Pleroma.Web.ErrorView, "500.json", []) ==
%{errors: %{detail: "Internal server error"}}
%{errors: %{detail: "Internal server error", reason: "nil"}}
end
test "render any other" do
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