Created
March 2, 2009 05:16
-
-
Save toolmantim/72622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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