From b1da5afac0a621c00765aec2de7887633a6210ae Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 27 Sep 2021 19:18:14 -0400 Subject: [PATCH] Fix JSON error pages --- lib/philomena_web/views/error_view.ex | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/philomena_web/views/error_view.ex b/lib/philomena_web/views/error_view.ex index 1439cf87..8bf8c1d0 100644 --- a/lib/philomena_web/views/error_view.ex +++ b/lib/philomena_web/views/error_view.ex @@ -25,13 +25,19 @@ defmodule PhilomenaWeb.ErrorView do def render(template, assigns) when template != "show.html" do {short_msg, long_msg} = @codes[assigns.status] || @codes[500] - render( - PhilomenaWeb.ErrorView, - "show.html", - conn: assigns.conn, - status: assigns.status, - short_msg: short_msg, - long_msg: long_msg - ) + case Phoenix.Controller.get_format(assigns.conn) do + "json" -> + %{"error" => short_msg} + + _ -> + render( + PhilomenaWeb.ErrorView, + "show.html", + conn: assigns.conn, + status: assigns.status, + short_msg: short_msg, + long_msg: long_msg + ) + end end end