exceptions 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/exceptions/backend.rb +8 -1
- data/lib/exceptions/backends/honeybadger.rb +8 -0
- data/lib/exceptions/version.rb +1 -1
- data/lib/exceptions.rb +2 -0
- data/lib/rack/exceptions.rb +23 -0
- data/spec/rack/exceptions_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c15fe46279fba52098310638efcf740aea4cf5
|
4
|
+
data.tar.gz: 4d2e6147476a91ce4e2f79f5571171f9c0664a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30fb87b9294da9fc9a2e4eb6823b96eaa46b9f7bccec2411f4e579aa822116846e53760220acbdcbc6db963129636b849cfa022473a755557768e3030999f727
|
7
|
+
data.tar.gz: 00e834877e5f2bdede316d038697f245f8c54fa164bc3553778a5a499db352b4b9cb01418683bf56576eedfc4580d4b09a996a2af514c86a4f6991dd25fb599f
|
data/lib/exceptions/backend.rb
CHANGED
@@ -10,7 +10,7 @@ module Exceptions
|
|
10
10
|
# exception - An Exception object.
|
11
11
|
# options - A Hash of options.
|
12
12
|
#
|
13
|
-
# Returns
|
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}"
|
data/lib/exceptions/version.rb
CHANGED
data/lib/exceptions.rb
CHANGED
@@ -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
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.
|
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
|