Created
September 24, 2010 13:28
-
-
Save darcy/595362 to your computer and use it in GitHub Desktop.
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
class ErrorHelper | |
def self.handle_exception(exception, params={}) | |
# ActiveSupport::Deprecation.warn("ErrorHelper has been deprecated. Use Exceptional#handle, Exceptional#rescue, or Exceptional#rescue_and_reraise instead.", caller) | |
params = filter_params(params) | |
Rails.logger.error exception.message | |
Rails.logger.error params.to_json if params | |
Rails.logger.error exception.backtrace.join("\n") if exception.backtrace | |
Exceptional.context params | |
Exceptional.handle exception | |
Exceptional.clear! | |
end | |
def self.handle_request_exception(exception, controller, request, params) | |
# ActiveSupport::Deprecation.warn("ErrorHelper has been deprecated. Use Exceptional#handle, Exceptional#rescue, or Exceptional#rescue_and_reraise instead.", caller) | |
params = filter_params(params) | |
Rails.logger.error exception.message | |
Rails.logger.error params.to_json if params | |
Rails.logger.error exception.backtrace.join("\n") if exception.backtrace | |
Exceptional::Catcher.handle_with_controller exception, controller, request | |
end | |
def self.rescue_and_reraise(name=nil, context={}, &block) | |
begin | |
block.call | |
rescue Exception => e | |
self.handle_exception(e,context) | |
raise(e) | |
end | |
end | |
private | |
def self.filter_params(params) | |
ApplicationController.new.send "filter_parameters", params.stringify_keys! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment