I’ve been seeing this error in the logs recently but I am not sure what it is being caused by:
[error] #PID<0.2222.0> running Service.Web.Endpoint terminated
Server: service.com:443 (https)
Request: POST /webhook
** (exit) an exception was raised:
** (Poison.EncodeError) unable to encode value: {:safe, ["" | "<p>500 — internal server error</p>\n"]}
(poison) lib/poison/encoder.ex:354: Poison.Encoder.Any.encode/2
(poison) lib/poison.ex:41: Poison.encode!/2
(phoenix) lib/phoenix/controller.ex:642: Phoenix.Controller.do_render/4
(phoenix) lib/phoenix/endpoint/render_errors.ex:58: Phoenix.Endpoint.RenderErrors.__catch__/5
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
I suppose I should somehow add “500.json” template or render clause to the ErrorView, but I am not sure. My current view looks like this
defmodule Service.Web.ErrorView do
use Service.Web, :view
def render("404.html", _assigns) do
render "not_found.html", %{}
end
def render("500.html", _assigns) do
render "internal.html", %{}
end
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
render "500.html", assigns
end
end
Is this a symptom of a bigger problem in my code since it wants to render 500 page for some reason? Would a longer stack-trace help? What is the usual way of dealing with problems like this (when the cause of the problem is not readily apparent) when they appear on a “production” machine?