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)?
This commit is contained in:
Daniel Uber 2021-12-27 11:39:15 -06:00 committed by GitHub
parent 0b8c09851c
commit 4d40ea18a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)