Permalink
Browse files

trap and warn about missing hoptoad

  • Loading branch information...
ddollar committed Mar 25, 2011
1 parent 0c038ab commit 6a418799ece42e2d94a869eb6ace0f18dbb840fe
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/taps/server.rb
View
@@ -1,14 +1,9 @@
-require 'hoptoad_notifier'
require 'sinatra/base'
require 'taps/config'
require 'taps/utils'
require 'taps/db_session'
require 'taps/data_stream'
-HoptoadNotifier.configure do |config|
- config.api_key = ENV["HOPTOAD_API_KEY"]
-end
-
module Taps
class Server < Sinatra::Base
use Rack::Auth::Basic do |login, password|
@@ -18,8 +13,17 @@ class Server < Sinatra::Base
use Rack::Deflater unless ENV['NO_DEFLATE']
error do
- HoptoadNotifier.notify(e)
e = request.env['sinatra.error']
+ begin
+ require 'hoptoad_notifier'
+ HoptoadNotifier.configure do |config|
+ config.api_key = ENV["HOPTOAD_API_KEY"]
+ end
+ HoptoadNotifier.notify(e)
+ rescue LoadError
+ puts "An error occurred but Hoptoad was not notified. To use Hoptoad, please"
+ puts "install the 'hoptoad_notifier' gem and set ENV[\"HOPTOAD_API_KEY\"]"
+ end
if e.kind_of?(Taps::BaseError)
content_type "application/json"
halt 412, { 'error_class' => e.class.to_s, 'error_message' => e.message, 'error_backtrace' => e.backtrace.join("\n") }.to_json

0 comments on commit 6a41879

Please sign in to comment.