require 'hoptoad/catcher'
require 'hoptoad/config'
module Hoptoad
# rails default ignores
IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
'ActionController::InvalidAuthenticityToken',
'CGI::Session::CookieStore::TamperedWithCookie']
IGNORE_DEFAULT.map!{|e| eval(e) rescue nil }.compact!
class << self
# Call this method to modify defaults in your initializers.
def configure
yield config
end
def config
@config ||= default_config
end
def reset_config
@config = default_config
end
# You can send an exception manually using this method, even when you are not in a
# controller. You can pass an exception or a hash that contains the attributes that
# would be sent to Hoptoad:
# * api_key: The API key for this project. The API key is a unique identifier that Hoptoad
# uses for identification.
# * error_message: The error returned by the exception (or the message you want to log).
# * backtrace: A backtrace, usually obtained with +caller+.
# * request: The controller's request object.
# * session: The contents of the user's session.
# * environment: ENV merged with the contents of the request's environment.
def notify(notice = {})
Sender.new.notify_hoptoad(notice)
end
private
def default_config
returning Hoptoad::Config.new do |config|
IGNORE_DEFAULT.each { |exception| config.ignore << exception }
end
end
end
config.instance_eval do
filter_backtrace do |line|
line.gsub(/#{RAILS_ROOT}/, "[RAILS_ROOT]")
end
filter_backtrace do |line|
line.gsub(/^\.\//, "")
end
filter_backtrace do |line|
Gem.path.inject(line) do |line, path|
line.gsub(/#{path}/, "[GEM_ROOT]")
end
end
end
# A dummy class for sending notifications manually outside of a controller.
class Sender
def rescue_action_in_public(exception)
end
include Hoptoad::Catcher
end
end