errorinbox 0.0.3a → 0.0.4a

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f69ae40c69fab22284b253a8dd5f20b45af1c21
4
+ data.tar.gz: e81ac62d271b789b435a6b8ebea43ffdb0a5eca1
5
+ SHA512:
6
+ metadata.gz: 49795aee9597820e55d40273a7386d8aecf62ec7da7636154afabc1ff398a74833854db419339a7552c69d58d8b50189d1f390c3a539da983fb82e13773cd3f5
7
+ data.tar.gz: fcd27aad1a2abb051626c66ad5f65044769c0625a29ecdd42691ec1209aead9252ccc753aa7a3c2e29b68a6b71d27dd41b52117ac1a5076a66453428610eab27
@@ -1,5 +1,13 @@
1
1
  module ErrorInbox
2
2
  class Configuration
3
3
  attr_accessor :username, :password
4
+ attr_writer :logger
5
+
6
+ def logger
7
+ @logger ||= begin
8
+ require "logger"
9
+ Logger.new(STDOUT)
10
+ end
11
+ end
4
12
  end
5
13
  end
@@ -3,31 +3,41 @@ require "json"
3
3
 
4
4
  module ErrorInbox
5
5
  class Notifier
6
+ HTTP_ERRORS = [
7
+ Timeout::Error,
8
+ Errno::EINVAL,
9
+ Errno::ECONNRESET,
10
+ EOFError,
11
+ Net::HTTPBadResponse,
12
+ Net::HTTPHeaderSyntaxError,
13
+ Net::ProtocolError,
14
+ Errno::ECONNREFUSED,
15
+ OpenSSL::SSL::SSLError
16
+ ].freeze
17
+
6
18
  def initialize(options)
7
19
  @options = options.dup
8
20
  end
9
21
 
10
22
  def save(ex)
11
- unless ErrorInbox.configuration.username && ErrorInbox.configuration.password
12
- raise MissingCredentialsError
13
- end
14
-
15
- uri = URI("http://oops.errorinbox.com/")
16
- req = Net::HTTP::Post.new(uri.path)
17
- req.basic_auth(ErrorInbox.configuration.username, ErrorInbox.configuration.password)
18
- req["Content-Type"] = "application/json"
19
- req.body = prepare_body(ex)
20
- res = Net::HTTP.start(uri.host, uri.port) do |http|
21
- http.request(req)
22
- end
23
+ if ErrorInbox.configuration.username && ErrorInbox.configuration.password
24
+ response = begin
25
+ http_request(prepare_body(ex))
26
+ rescue *HTTP_ERRORS => ex
27
+ ErrorInbox.configuration.logger.error("#{ex.class.name}: #{ex.message}")
28
+ nil
29
+ end
23
30
 
24
- case res
25
- when Net::HTTPCreated
26
- JSON.load(res.body)["id"]
27
- when Net::HTTPForbidden
28
- raise InvalidCredentialsError
31
+ case response
32
+ when Net::HTTPCreated
33
+ JSON.load(response.body)["id"]
34
+ else
35
+ ErrorInbox.configuration.logger.error(response.class.name)
36
+ {}
37
+ end
29
38
  else
30
- raise "Unknow error: #{res}"
39
+ ErrorInbox.configuration.logger.error("Missing credentials configuration")
40
+ {}
31
41
  end
32
42
  end
33
43
 
@@ -66,5 +76,18 @@ module ErrorInbox
66
76
 
67
77
  JSON.dump(body)
68
78
  end
79
+
80
+ def http_request(body)
81
+ uri = URI("http://oops.errorinbox.com/")
82
+ http = Net::HTTP.new(uri.host, uri.port)
83
+ http.read_timeout = 5
84
+ http.open_timeout = 2
85
+
86
+ request = Net::HTTP::Post.new(uri.request_uri)
87
+ request["Content-Type"] = "application/json"
88
+ request.body = body
89
+ request.basic_auth(ErrorInbox.configuration.username, ErrorInbox.configuration.password)
90
+ http.request(request)
91
+ end
69
92
  end
70
93
  end
@@ -1,3 +1,3 @@
1
1
  module ErrorInbox
2
- VERSION = "0.0.3a"
2
+ VERSION = "0.0.4a"
3
3
  end
@@ -10,19 +10,25 @@ describe ErrorInbox::Notifier do
10
10
  end
11
11
 
12
12
  it "raises an error if credentials are missing" do
13
- ErrorInbox.stub(:configuration => double("configuration", :username => nil, :password => nil))
13
+ ErrorInbox.stub(:configuration => double("configuration", :username => nil, :password => nil, :logger => logger = double("logger")))
14
+ logger.
15
+ should_receive(:error).
16
+ with("Missing credentials configuration")
14
17
 
15
18
  notifier = described_class.new(:rack_env => { :foo => "bar" })
16
- expect { notifier.save(ex) }.to raise_error(ErrorInbox::MissingCredentialsError)
19
+ expect(notifier.save(ex)).to eq({})
17
20
  end
18
21
 
19
22
  it "raises an error if credentials are invalid" do
20
- ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar"))
23
+ ErrorInbox.stub(:configuration => double("configuration", :username => "foo", :password => "bar", :logger => logger = double("logger")))
24
+ logger.
25
+ should_receive(:error).
26
+ with("Net::HTTPForbidden")
21
27
 
22
28
  stub_forbidden_request
23
29
 
24
30
  notifier = described_class.new(:rack_env => { :foo => "bar" })
25
- expect { notifier.save(ex) }.to raise_error(ErrorInbox::InvalidCredentialsError)
31
+ expect(notifier.save(ex)).to eq({})
26
32
  end
27
33
 
28
34
  it "sends rack exception" do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errorinbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3a
5
- prerelease: 5
4
+ version: 0.0.4a
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rafael Souza
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,17 +27,15 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Send exceptions to errorinbox.com
@@ -70,30 +65,26 @@ files:
70
65
  homepage: http://github.com/rafaelss/errorinbox
71
66
  licenses:
72
67
  - MIT
68
+ metadata: {}
73
69
  post_install_message:
74
70
  rdoc_options: []
75
71
  require_paths:
76
72
  - lib
77
73
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
74
  requirements:
80
- - - ! '>='
75
+ - - '>='
81
76
  - !ruby/object:Gem::Version
82
77
  version: '0'
83
- segments:
84
- - 0
85
- hash: -1856483604331423650
86
78
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
79
  requirements:
89
- - - ! '>'
80
+ - - '>'
90
81
  - !ruby/object:Gem::Version
91
82
  version: 1.3.1
92
83
  requirements: []
93
84
  rubyforge_project:
94
- rubygems_version: 1.8.23
85
+ rubygems_version: 2.0.3
95
86
  signing_key:
96
- specification_version: 3
87
+ specification_version: 4
97
88
  summary: Capture and send all exceptions raised by your app to errorinbox.com
98
89
  test_files:
99
90
  - spec/error_inbox/notifier_spec.rb