Created
May 4, 2012 15:12
-
-
Save marcomorain/2595406 to your computer and use it in GitHub Desktop.
This file contains 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
class ApplicationController < ActionController::Base | |
unless Rails.application.config.consider_all_requests_local | |
rescue_from ActionController::RoutingError, :with => :render_404 | |
rescue_from ActiveRecord::RecordNotFound, :with => :render_404 | |
rescue_from ActionController::UnknownAction, :with => :render_404 | |
rescue_from ActionController::UnknownController, :with => :render_404 | |
rescue_from Exception, :with => :render_500 | |
end | |
# Called from the bottom of config/routes.rb for all non-exiting routes | |
def render_bad_route | |
logger.error("Bad route '#{params['a']}'; '#{request.url}'; '#{request.remote_ip}';, '#{request.user_agent}'") | |
common_error_handler(404, "404 Not Found", "The page you were looking for couldn't be found.") | |
end | |
private | |
def render_404(exception) | |
Exceptional.handle(exception) | |
logger.error(exception) | |
common_error_handler(404, "404 Not Found", "The page you were looking for couldn't be found.") | |
end | |
def render_500(exception) | |
Exceptional.handle(exception) | |
logger.error(exception) | |
common_error_handler(500, "500 Internal Error", "An error has occurred on the page you were trying to access. We've been notified about this issue and we'll take a look at it shortly. We apologize for any inconvenience.") | |
end | |
def common_error_handler(code, short_message, long_message) | |
@error_message = long_message | |
respond_to do |format| | |
format.html { render :template => 'application/error_template', :status => code } | |
format.json { render :text => long_message, :status => code } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment