Skip to content

Instantly share code, notes, and snippets.

@jasonm
Created August 11, 2009 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonm/166112 to your computer and use it in GitHub Desktop.
Save jasonm/166112 to your computer and use it in GitHub Desktop.
# generic module that holds configuration and serves as namespace
module Hoptoad
mattr_accessor :api_key
end
# framework-agnostic data structure holding Hoptoad-specific fields
class Hoptoad::Notice
class Error
def backtrace=(backtrace)
# properly handle array of strings, maybe stored internally as an array of H::N::Line objects
end
end
def initialize
request = Hoptoad::Notice::Request.new
error = Hoptoad::Notice::Error.new
server_environment = Hoptoad::Notice::ServerEnvironment.new
notifier = # sets up notifier information with constants from Hoptoad module
api_key = Hoptoad.api_key
end
attr_reader :request, :error, :server_environment, :notifier, :api_key
def error=(exception)
error.class = exception.class.name
error.message = exception.message
error.backtrace = exception.backtrace
end
def to_xml
end
def valid?
end
end
# framework-agnostic class that submits a Notice to Hoptoad
class Hoptoad::Submitter
def self.submit(notice)
xml = notice.to_xml
http = HTTP.new
http.post(xml)
end
end
# framework-specific class that catches some exceptional behavior, populates a Notice, and
# calls Submitter
class Hoptoad::Catcher::RailsCatcher
def self.included(base)
# does some chaining for rescue_action_in_public etc.
end
def rescue_action_in_public_with_hoptoad(exception)
notify_hoptoad(exception) unless ignore?(exception) || ignore_user_agent?
rescue_action_in_public_without_hoptoad(exception)
end
def notify_hoptoad(exception)
exception = exception.dup
notice = Notice.new
# populate notice attrs based on exception
notice.request.url = request.url
notice.error = exception
# do any Rails-specific filtering
notice.request.params = filter_hash(request.parameters)
notice.error.backtrace = filter_backtrace(notice.error.backtrace)
# submits via Submitter
Hoptoad::Submitter.submit(notice)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment