Skip to content

Instantly share code, notes, and snippets.

@toolmantim
Created March 2, 2009 05:16
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 toolmantim/72622 to your computer and use it in GitHub Desktop.
Save toolmantim/72622 to your computer and use it in GitHub Desktop.
# Example of using Hoptoad from a Sinatra app.
#
# This uses the existing Rails plugin with a hacky workaround for RAILS_ENV
# and RAILS_ROOT - better for now than recreating a whole plugin and duplicating
# all the config, backtrace cleaning, etc. I'm hoping this provides an example
# for a future version of the notifier plugin that supports various
# frameworks.
require 'rubygems'
gem 'sinatra', '~> 0.9.0'
require 'sinatra'
gem 'thoughtbot-hoptoad_notifier', '= 1.1'
require 'hoptoad_notifier'
HoptoadNotifier.api_key = 'YOUR_API_KEY'
RAILS_ENV = Sinatra::Application.environment
RAILS_ROOT = File.expand_path(File.dirname(__FILE__))
class HoptoadNotifier::Sinatra
def self.notify(request)
error = request.env['sinatra.error']
HoptoadNotifier.notify(
:error_class => error.class.name,
:error_message => "#{error.class.name}: #{error.message}",
:backtrace => error.backtrace,
:environment => request.env,
:request => { :params => request.params, :url => request.url }
)
end
end
get '/' do
raise "Eeep!"
end
error do
HoptoadNotifier::Sinatra.notify(request)
"Something went boom"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment