Created
November 29, 2012 06:34
-
-
Save nauman/4167182 to your computer and use it in GitHub Desktop.
catch all exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#catch all exceptions | |
unless Rails.application.config.consider_all_requests_local | |
rescue_from Exception, with: :render_500 | |
rescue_from ActionController::RoutingError, with: :render_404 | |
rescue_from ActionController::UnknownController, with: :render_404 | |
rescue_from ActionController::UnknownAction, with: :render_404 | |
rescue_from ActiveRecord::RecordNotFound, with: :render_404 | |
end | |
private | |
#generate json messages: | |
def render_404(exception) | |
render :json => exception.message | |
end | |
def render_500(exception) | |
render :json => exception.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment