Skip to content

Instantly share code, notes, and snippets.

@agius
Created October 12, 2013 00:11
Show Gist options
  • Select an option

  • Save agius/6943968 to your computer and use it in GitHub Desktop.

Select an option

Save agius/6943968 to your computer and use it in GitHub Desktop.
Centralized error reporting module - control what services you use and how you log errors in one place.
module Blunder
# Centralizes error reporting, so we don't get custom
# library names like BugSnag or Errplane all over our code
def self.oops(exception, custom_data = {})
raise if Rails.env == 'test'
exception = Exception.new(exception) unless exception.is_a?(Exception)
custom_data = custom_data.with_indifferent_access
Rails.logger.error("\n\nBlunder Exception: #{exception}")
Rails.logger.error("backtrace:#{exception.backtrace.take(20).join("\n")}\n\n") if exception.backtrace.present?
env = custom_data.delete(:env)
if %w(staging production).include?(Rails.env)
Bugsnag.notify(exception, custom_data)
ExceptionNotifier.notify_exception(exception, env: env, data: custom_data)
end
end
# used for testing error reporting in delayed job
class DelayedBlunder
include Sidekiq::Worker
def self.generate_error
raise "delayed error test"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment