Created
August 21, 2009 19:17
-
-
Save house9/172342 to your computer and use it in GitHub Desktop.
ApplicationController#handler_exception
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 | |
helper :all # include all helpers, all the time | |
# ... | |
rescue_from Exception, :with => :handler_exception | |
# ... | |
def handler_exception(exception) | |
if request.xhr? then | |
message = "Error: #{exception.class.to_s}" | |
message += " in #{request.parameters['controller'].camelize}Controller" if request.parameters['controller'] | |
message += "##{request.parameters['action']}" if request.parameters['action'] | |
message += "\n#{exception.clean_message}" | |
message += "\n\nFull Trace:\n#{exception.clean_backtrace.join("\n")}" | |
message += "\n\nRequest:\n#{params.inspect.gsub(',', ",\n")}" | |
# log the error | |
logger.fatal "#{message}" | |
message = "ajaxError, check the server logs for details" unless local_request? | |
respond_to do |wants| | |
wants.js { render :text => message, :status => :internal_server_error } | |
end | |
else | |
# not an ajax request, use the default handling; | |
# actionpack-2.2.2/lib/action_controller/rescue.rb | |
rescue_action_without_handler(exception) | |
end | |
return # don't risk DoubleRenderError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment