Initial commit
This commit is contained in:
25
config/initializers/exception_reporting.rb
Normal file
25
config/initializers/exception_reporting.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
def catch_and_report_exception(options = {})
|
||||
begin
|
||||
yield
|
||||
nil
|
||||
rescue options.fetch(:class) { StandardError } => e
|
||||
report_exception(e)
|
||||
e
|
||||
end
|
||||
end
|
||||
|
||||
def report_exception(exception, report_to_ets = true)
|
||||
report_exception_to_screen(exception)
|
||||
report_exception_to_ets(exception) if report_to_ets
|
||||
end
|
||||
|
||||
def report_exception_to_screen(exception)
|
||||
Rails.logger.unknown exception.inspect
|
||||
Rails.logger.unknown exception.backtrace.join("\n") if exception.respond_to?(:backtrace)
|
||||
end
|
||||
|
||||
def report_exception_to_ets(exception)
|
||||
Raven.capture_exception(exception) if defined?(Raven)
|
||||
rescue => ets_exception
|
||||
report_exception(ets_exception, false)
|
||||
end
|
||||
Reference in New Issue
Block a user