Phoenix - returning custom 500 (Internal Server Error). How to?

Thanks, I eventually managed to do it with defimpl.
I’m writing here the solution, it might help others with similar issues:
In the myapp_web.ex:

defmodule Myapp.Customerror do
  defexception [:message]
end


defimpl Plug.Exception, for: Myapp.Customerror do
  def status(_exception), do: 500
end

error_view.ex:

  def render("500.json", %{conn: conn}) do
    %{error: conn.assigns.reason.message}
  end

.Finally, in my code:

raise Myapp.Customerror, "My custom message"

Cheers,
T.