]> cat aescling's git repositories - mastodon.git/commitdiff
Fix HTML error pages being returned when JSON is expected (#12713)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 30 Dec 2019 03:38:18 +0000 (04:38 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Dec 2019 03:38:18 +0000 (04:38 +0100)
Fix #12509
See also #12214

app/controllers/application_controller.rb

index ca5229f7966d08cc9c12cf0454009286dcbbc8a1..3f92053813f2ceda0805c363f2a1b5ec62d13c08 100644 (file)
@@ -136,6 +136,9 @@ class ApplicationController < ActionController::Base
   end
 
   def respond_with_error(code)
-    render "errors/#{code}", layout: 'error', status: code, formats: [:html]
+    respond_to do |format|
+      format.any  { render "errors/#{code}", layout: 'error', status: code, formats: [:html] }
+      format.json { render json: { error: Rack::Utils::HTTP_STATUS_CODES[code] }, status: code }
+    end
   end
 end