Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Error responses cleanup (mastodon#2692)
Browse files Browse the repository at this point in the history
* Use respond_with_error for forbidden errors

* Wrap up common error code into single method
  • Loading branch information
mjankowski authored and Gargron committed May 1, 2017
1 parent 2bd46f4 commit 7bffd16
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,20 @@ def check_suspension

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?
Expand Down Expand Up @@ -105,7 +93,12 @@ def cache_collection(raw, klass)
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

0 comments on commit 7bffd16

Please sign in to comment.