errorinbox 0.0.5a → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/error_inbox/configuration.rb +8 -0
- data/lib/error_inbox/notifier.rb +18 -5
- data/lib/error_inbox/version.rb +1 -1
- data/spec/error_inbox/configuration_spec.rb +7 -0
- data/spec/error_inbox/notifier_spec.rb +31 -13
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f08056c5e1cf6d6a2e44c6975ebc3b2bf0c18ae3
|
4
|
+
data.tar.gz: e0eb73759a28cc103b4c0caa0c8f6c5e0ca00701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f90fd70d5100bf8603ce1e1b3755fc348cc2819263c2527f8f465f607e7638680cee551e2946adca031a76bb949036ffe546cca177b4a161225b3e0694f1110d
|
7
|
+
data.tar.gz: 53f0bb3ae6fa6db265f8343a0b773ebdd509f409cbe0d68794050ae1c9cbcd0ed34ef8bc924ce4dc5fce777a4a48cec9d202e0489176fc87e7308f5471948740
|
data/lib/error_inbox/notifier.rb
CHANGED
@@ -20,11 +20,16 @@ module ErrorInbox
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def save(ex)
|
23
|
-
if
|
23
|
+
if configuration.username && configuration.password
|
24
|
+
if ignored?(ex)
|
25
|
+
configuration.logger.info("#{ex.class.name}: ignored")
|
26
|
+
return {}
|
27
|
+
end
|
28
|
+
|
24
29
|
response = begin
|
25
30
|
http_request(prepare_body(ex))
|
26
31
|
rescue *HTTP_ERRORS => ex
|
27
|
-
|
32
|
+
configuration.logger.error("#{ex.class.name}: #{ex.message}")
|
28
33
|
nil
|
29
34
|
end
|
30
35
|
|
@@ -32,17 +37,21 @@ module ErrorInbox
|
|
32
37
|
when Net::HTTPCreated
|
33
38
|
JSON.load(response.body)["id"]
|
34
39
|
else
|
35
|
-
|
40
|
+
configuration.logger.error(response.class.name)
|
36
41
|
{}
|
37
42
|
end
|
38
43
|
else
|
39
|
-
|
44
|
+
configuration.logger.error("Missing credentials configuration")
|
40
45
|
{}
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
49
|
protected
|
45
50
|
|
51
|
+
def ignored?(ex)
|
52
|
+
!!configuration.ignores.find { |blk| blk.call(ex, @options) }
|
53
|
+
end
|
54
|
+
|
46
55
|
def prepare_body(ex)
|
47
56
|
body = {
|
48
57
|
:type => ex.class.name,
|
@@ -86,8 +95,12 @@ module ErrorInbox
|
|
86
95
|
request = Net::HTTP::Post.new(uri.request_uri)
|
87
96
|
request["Content-Type"] = "application/json"
|
88
97
|
request.body = body
|
89
|
-
request.basic_auth(
|
98
|
+
request.basic_auth(configuration.username, configuration.password)
|
90
99
|
http.request(request)
|
91
100
|
end
|
101
|
+
|
102
|
+
def configuration
|
103
|
+
ErrorInbox.configuration
|
104
|
+
end
|
92
105
|
end
|
93
106
|
end
|
data/lib/error_inbox/version.rb
CHANGED
@@ -2,6 +2,8 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ErrorInbox::Notifier do
|
4
4
|
let(:ex) { double("exception", :message => "some message", :backtrace => ["a.rb:10", "b.rb:11"]) }
|
5
|
+
let(:configuration) { double("configuration", :username => nil, :password => nil, :ignores => []) }
|
6
|
+
let(:logger) { double("logger") }
|
5
7
|
|
6
8
|
around do |example|
|
7
9
|
Timecop.travel(2013, 8, 21, 11, 57, 0) do
|
@@ -10,7 +12,8 @@ describe ErrorInbox::Notifier do
|
|
10
12
|
end
|
11
13
|
|
12
14
|
it "raises an error if credentials are missing" do
|
13
|
-
ErrorInbox.stub(:configuration =>
|
15
|
+
ErrorInbox.stub(:configuration => configuration)
|
16
|
+
configuration.stub(:logger => logger)
|
14
17
|
logger.
|
15
18
|
should_receive(:error).
|
16
19
|
with("Missing credentials configuration")
|
@@ -20,7 +23,8 @@ describe ErrorInbox::Notifier do
|
|
20
23
|
end
|
21
24
|
|
22
25
|
it "raises an error if credentials are invalid" do
|
23
|
-
ErrorInbox.stub(:configuration =>
|
26
|
+
ErrorInbox.stub(:configuration => configuration)
|
27
|
+
configuration.stub(:username => "foo", :password => "bar", :logger => logger)
|
24
28
|
logger.
|
25
29
|
should_receive(:error).
|
26
30
|
with("Net::HTTPForbidden")
|
@@ -31,22 +35,36 @@ describe ErrorInbox::Notifier do
|
|
31
35
|
expect(notifier.save(ex)).to eq({})
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
context "with valid credentials" do
|
39
|
+
before do
|
40
|
+
configuration.stub(:username => "foo", :password => "bar")
|
36
41
|
|
37
|
-
|
42
|
+
ErrorInbox.stub(:configuration => configuration)
|
43
|
+
end
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
it "sends rack exception" do
|
46
|
+
stub_created_request_for_rack_exception
|
47
|
+
|
48
|
+
notifier = described_class.new(:rack_env => { :foo => "bar" })
|
49
|
+
expect(notifier.save(ex)).to eq(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "sends any other exception" do
|
53
|
+
stub_created_request_for_any_exception
|
42
54
|
|
43
|
-
|
44
|
-
|
55
|
+
notifier = described_class.new(:sidekiq => { :queue => "default" })
|
56
|
+
expect(notifier.save(ex)).to eq(1)
|
57
|
+
end
|
45
58
|
|
46
|
-
|
59
|
+
it "does not send ignored exceptions" do
|
60
|
+
configuration.stub(:ignores => [proc{ |ex, o| true }], :logger => logger)
|
61
|
+
logger.
|
62
|
+
should_receive(:info).
|
63
|
+
with("RSpec::Mocks::Mock: ignored")
|
47
64
|
|
48
|
-
|
49
|
-
|
65
|
+
notifier = described_class.new(:rack_env => { :foo => "bar" })
|
66
|
+
expect(notifier.save(ex)).to eq({})
|
67
|
+
end
|
50
68
|
end
|
51
69
|
|
52
70
|
def stub_created_request_for_rack_exception
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errorinbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Souza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/error_inbox/rack.rb
|
59
59
|
- lib/error_inbox/version.rb
|
60
60
|
- lib/errorinbox.rb
|
61
|
+
- spec/error_inbox/configuration_spec.rb
|
61
62
|
- spec/error_inbox/notifier_spec.rb
|
62
63
|
- spec/error_inbox/rack_spec.rb
|
63
64
|
- spec/error_inbox_spec.rb
|
@@ -77,9 +78,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- - '
|
81
|
+
- - '>='
|
81
82
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
+
version: '0'
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project:
|
85
86
|
rubygems_version: 2.0.3
|
@@ -87,6 +88,7 @@ signing_key:
|
|
87
88
|
specification_version: 4
|
88
89
|
summary: Capture and send all exceptions raised by your app to errorinbox.com
|
89
90
|
test_files:
|
91
|
+
- spec/error_inbox/configuration_spec.rb
|
90
92
|
- spec/error_inbox/notifier_spec.rb
|
91
93
|
- spec/error_inbox/rack_spec.rb
|
92
94
|
- spec/error_inbox_spec.rb
|