Sha256: 5391b438f6774bd6f339393bd48abb5d5747b1b55f76631409c1e301291915b6
Contents?: true
Size: 1.96 KB
Versions: 15
Compression:
Stored size: 1.96 KB
Contents
require 'rack' require 'honeybadger' require 'forwardable' module Honeybadger module Rack # Public: Middleware for Rack applications. Any errors raised by the upstream # application will be delivered to Honeybadger and re-raised. # # Examples: # # require 'honeybadger/rack/error_notifier' # # Honeybadger.configure do |config| # config.api_key = 'my_api_key' # end # # app = Rack::Builder.app do # run lambda { |env| raise "Rack down" } # end # # use Honeybadger::Rack::ErrorNotifier # run app # # Use a standard Honeybadger.configure call to configure your api key. class ErrorNotifier extend Forwardable def initialize(app, config) @app = app @config = config end def call(env) config.with_request(::Rack::Request.new(env)) do begin env['honeybadger.config'] = config response = @app.call(env) rescue Exception => raised env['honeybadger.error_id'] = notify_honeybadger(raised, env) raise end framework_exception = framework_exception(env) if framework_exception env['honeybadger.error_id'] = notify_honeybadger(framework_exception, env) end response end ensure Honeybadger.context.clear! end private attr_reader :config def_delegator :@config, :logger def ignored_user_agent?(env) true if config[:'exceptions.ignored_user_agents']. flatten. any? { |ua| ua === env['HTTP_USER_AGENT'] } end def notify_honeybadger(exception, env) return if ignored_user_agent?(env) Honeybadger.notify_or_ignore(exception) end def framework_exception(env) env['action_dispatch.exception'] || env['rack.exception'] || env['sinatra.error'] || env['honeybadger.exception'] end end end end
Version data entries
15 entries across 15 versions & 1 rubygems