From 4d40ea18a2ccfaebef2d687e40a83c3992634759 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Mon, 27 Dec 2021 11:39:15 -0600 Subject: [PATCH] When returning a json error, don't use a raw unescaped string (#15879) The 400 and 403 error pages show json parsing errors in most browsers, since "Error: Bad Request" is not a valid json body ('"Error: Bad Request"' would be, or the object with key error and value of the string which I've selected is _also_ valid). Do we have frontend code that's looking for this body before it parses for some reason, or was this just a mistaken copying from the api controller in the initial PRs (#2293 for not_authorized, and #6248 for the bad_request method, which may have just replicated the decision for not_authorized)? --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dbf64b723..a314faff7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -74,12 +74,12 @@ class ApplicationController < ActionController::Base end def not_authorized - render json: "Error: not authorized", status: :unauthorized + render json: {error: "Error: not authorized"}, status: :unauthorized raise NotAuthorizedError, "Unauthorized" end def bad_request - render json: "Error: Bad Request", status: :bad_request + render json: {error: "Error: Bad Request"}, status: :bad_request end def error_too_many_requests(exc)