about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-01 16:24:36 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-01 22:24:36 +0200
commit7bffd16024303400e432c0db55314a2dd2d7fedd (patch)
tree4a70b913004bddbb8b52c2a8a31100051faff275 /app
parent2bd46f442dfdb7d1f2ddddaba56900807f7e7ce9 (diff)
Error responses cleanup (#2692)
* Use respond_with_error for forbidden errors

* Wrap up common error code into single method
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb35
1 files changed, 14 insertions, 21 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 8456095fb..d4428c054 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -44,32 +44,20 @@ class ApplicationController < ActionController::Base
 
   protected
 
-  def not_found
-    respond_to do |format|
-      format.any  { head 404 }
-      format.html { respond_with_error(404) }
-    end
+  def forbidden
+    respond_with_error(403)
   end
 
-  def gone
-    respond_to do |format|
-      format.any  { head 410 }
-      format.html { respond_with_error(410) }
-    end
+  def not_found
+    respond_with_error(404)
   end
 
-  def forbidden
-    respond_to do |format|
-      format.any  { head 403 }
-      format.html { render 'errors/403', layout: 'error', status: 403 }
-    end
+  def gone
+    respond_with_error(410)
   end
 
   def unprocessable_entity
-    respond_to do |format|
-      format.any  { head 422 }
-      format.html { respond_with_error(422) }
-    end
+    respond_with_error(422)
   end
 
   def single_user_mode?
@@ -105,7 +93,12 @@ class ApplicationController < ActionController::Base
   end
 
   def respond_with_error(code)
-    set_locale
-    render "errors/#{code}", layout: 'error', status: code
+    respond_to do |format|
+      format.any  { head code }
+      format.html do
+        set_locale
+        render "errors/#{code}", layout: 'error', status: code
+      end
+    end
   end
 end