Phoenix do not take into consideration my custom errorView

  1. What headers do you have? Have you sent Accept: application/json?
  2. Matching by template name is invalid. In case of 404, the template is the following: 404.json, not error.json.
  3. The second parameter is not an exception, but assigns. The exception could be found in assigns.reason.

If you want generic handler for JSON format:

def render(<<_::binary-size(3)>> <> ".json" = template, assigns) do
  %{
    error: Phoenix.Controller.status_message_from_template(template),
    description: Exception.message(assigns.reason)
  }
end

but don’t show a message from all exceptions, as they may contain not public information