about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-12-30 04:38:18 +0100
committerGitHub <noreply@github.com>2019-12-30 04:38:18 +0100
commit353c94910bf02e2cd7f82ae47a55af3164926b3d (patch)
tree6bb65f6329684ffd2876a565f774cbd5ad822b55 /app/controllers
parentca78b1473ec6ea10ea0b42916dc1240371437027 (diff)
Fix HTML error pages being returned when JSON is expected (#12713)
Fix #12509
See also #12214
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application_controller.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index ca5229f79..3f9205381 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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