exceptions 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 679a7d117a8e0ac3c2f079b7947b219ff60ff866
4
- data.tar.gz: 8418db0bdcbbf795c5b33627b473f81161ca84fd
3
+ metadata.gz: 69c15fe46279fba52098310638efcf740aea4cf5
4
+ data.tar.gz: 4d2e6147476a91ce4e2f79f5571171f9c0664a9a
5
5
  SHA512:
6
- metadata.gz: 3ff94de0005f7daf48045c1bf1ea6bd2c1ddb153f76cd0ec3f66e8567f9a4de3aa10005e08f16c757faba72dfdd7603e4d257ac990d0271cbebc6f9c943ba4d2
7
- data.tar.gz: 911fa746e3b027b504020abe31eb666479f17af7f62dc53c54126131a33f9153acced39f326ab2ca781b13ccad970ecc67291060df4d57614478f8378ff391cd
6
+ metadata.gz: 30fb87b9294da9fc9a2e4eb6823b96eaa46b9f7bccec2411f4e579aa822116846e53760220acbdcbc6db963129636b849cfa022473a755557768e3030999f727
7
+ data.tar.gz: 00e834877e5f2bdede316d038697f245f8c54fa164bc3553778a5a499db352b4b9cb01418683bf56576eedfc4580d4b09a996a2af514c86a4f6991dd25fb599f
@@ -10,7 +10,7 @@ module Exceptions
10
10
  # exception - An Exception object.
11
11
  # options - A Hash of options.
12
12
  #
13
- # Returns nil or a Result object.
13
+ # Returns an object satisfying the Result interface.
14
14
  def notify(exception)
15
15
  raise NotImplementedError
16
16
  end
@@ -28,5 +28,12 @@ module Exceptions
28
28
  # Returns nothing.
29
29
  def clear_context
30
30
  end
31
+
32
+ # Public: Called by the Rack middleware when an exception is raised.
33
+ #
34
+ # Returns and object satisfying the Result interface.
35
+ def rack_exception(exception, env)
36
+ notify(exception)
37
+ end
31
38
  end
32
39
  end
@@ -21,6 +21,14 @@ module Exceptions
21
21
  ::Honeybadger.clear!
22
22
  end
23
23
 
24
+ def rack_exception(exception, env)
25
+ notify(exception, rack_env: env) unless ::Honeybadger.
26
+ configuration.
27
+ ignore_user_agent.
28
+ flatten.
29
+ any? { |ua| ua === env['HTTP_USER_AGENT'] }
30
+ end
31
+
24
32
  class Result < ::Exceptions::Result
25
33
  def url
26
34
  "https://www.honeybadger.io/notice/#{id}"
@@ -1,3 +1,3 @@
1
1
  module Exceptions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/exceptions.rb CHANGED
@@ -4,6 +4,8 @@ require 'exceptions/result'
4
4
  require 'exceptions/backend'
5
5
  require 'exceptions/backends'
6
6
 
7
+ require 'rack/exceptions'
8
+
7
9
  module Exceptions
8
10
  class << self
9
11
  # Public: Forwards the exception to the configured backend.
@@ -0,0 +1,23 @@
1
+ module Rack
2
+ class Exceptions
3
+ attr_reader :backend
4
+
5
+ def initialize(app, backend = nil)
6
+ @app = app
7
+ @backend = backend || ::Exceptions.configuration.backend
8
+ end
9
+
10
+ def call(env)
11
+ begin
12
+ response = @app.call(env)
13
+ rescue Exception => e
14
+ backend.rack_exception(e, env)
15
+ raise
16
+ end
17
+
18
+ response
19
+ ensure
20
+ backend.clear_context
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::Exceptions, foo: true do
4
+ let(:response) { [200, {}, []] }
5
+ let(:app) { double('app', call: response) }
6
+ let(:middleware) { described_class.new app }
7
+
8
+ describe '#call' do
9
+ context 'when no exception is raised' do
10
+ it 'returns the response' do
11
+ expect(middleware.call({})).to eq response
12
+ end
13
+ end
14
+
15
+ context 'when an exception is raised' do
16
+ before do
17
+ expect(app).to receive(:call).and_raise(boom)
18
+ end
19
+
20
+ it 'tracks the error' do
21
+ expect { middleware.call({}) }.to raise_error
22
+ end
23
+ end
24
+ end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,8 @@ RSpec.configure do |config|
11
11
  with_backend(BACKENDS[backend]) do
12
12
  example.run
13
13
  end
14
+ else
15
+ example.run
14
16
  end
15
17
  end
16
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
@@ -91,8 +91,10 @@ files:
91
91
  - lib/exceptions/configuration.rb
92
92
  - lib/exceptions/result.rb
93
93
  - lib/exceptions/version.rb
94
+ - lib/rack/exceptions.rb
94
95
  - spec/exceptions/backends/honeybadger/integration_spec.rb
95
96
  - spec/exceptions/backends/logger/integration_spec.rb
97
+ - spec/rack/exceptions_spec.rb
96
98
  - spec/spec_helper.rb
97
99
  - spec/support/honeybadger.rb
98
100
  homepage: https://github.com/remind101/exceptions
@@ -122,5 +124,6 @@ summary: Exceptions is a Ruby gem for exception tracking.
122
124
  test_files:
123
125
  - spec/exceptions/backends/honeybadger/integration_spec.rb
124
126
  - spec/exceptions/backends/logger/integration_spec.rb
127
+ - spec/rack/exceptions_spec.rb
125
128
  - spec/spec_helper.rb
126
129
  - spec/support/honeybadger.rb