error_notifier 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ module ErrorNotifier
2
+ class Configuration
3
+ attr_accessor :url, :site
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module ErrorNotifier
2
+ class Rack
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ begin
9
+ @app.call(env)
10
+ rescue Exception => e
11
+ ErrorNotifier.send(e, extract_data(env))
12
+ raise
13
+ end
14
+ end
15
+
16
+ def extract_data(env)
17
+ {:url => env['REQUEST_URI'], :ua => env['HTTP_USER_AGENT']}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'error_notifier/rack'
2
+ require_relative 'error_notifier/configuration'
3
+
4
+ require 'json'
5
+ require 'rest_client'
6
+
7
+ module ErrorNotifier
8
+ Version = '0.0.4'
9
+
10
+ class << self
11
+ attr_accessor :configuration
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def configure
18
+ yield(configuration)
19
+ end
20
+
21
+ def send(exception, data = {})
22
+ exception = unwrap(exception)
23
+ data[:message] = exception.inspect
24
+ data[:stack] = exception.backtrace.join('\n')
25
+ data[:site] = @configuration.site
26
+ begin
27
+ RestClient.post(@configuration.url, data.to_json, :content_type => :json, :accept => :json)
28
+ rescue
29
+ nil
30
+ end
31
+ end
32
+
33
+ def unwrap(exception)
34
+ return exception.original_exception if exception.respond_to?(:original_exception)
35
+ return exception.continued_exception if exception.respond_to?(:continued_exception)
36
+ exception
37
+ end
38
+ end
39
+ end
data/license ADDED
@@ -0,0 +1,14 @@
1
+ This file is part of ErrorNotify.
2
+
3
+ ErrorNotify is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ ErrorNotify is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU General Public License for more details.
12
+
13
+ You should have received a copy of the GNU General Public License
14
+ along with MongoLight. If not, see <http://www.gnu.org/licenses/>.
data/readme.markdown ADDED
@@ -0,0 +1,24 @@
1
+ # ErrorNotifier #
2
+ Posts exceptions to a web service. Useful for use in Rack applications.
3
+
4
+ ## Configuration ##
5
+ Configure ErrorNotifier via `ErrorNotifier.configure`:
6
+
7
+ ErrorNotifier.configure do |config|
8
+ config.url = 'http://health.mysite.com/errors'
9
+ config.site = 'mysite' #an identifier for this site
10
+ end
11
+
12
+ ## Sending ##
13
+ Use `ErrorNotifier.send` to send exceptions:
14
+
15
+ ErrorNotifier.send(e)
16
+ # or, with options
17
+ ErrorNotifier.send(e, {:user => @current_user})
18
+
19
+ ## Rack ##
20
+ `ErrorNotifier::Rack` is a rack middleware which will capture exceptions and post them to the specified site. For example, in Rails, once need only specify:
21
+
22
+ config.middleware.use ErrorNotifier::Rack
23
+
24
+ within `application.rb`
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error_notifier
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.4
6
+ platform: ruby
7
+ authors:
8
+ - Karl Seguin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-06-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.6.7
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.4.1
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.3
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description:
49
+ email:
50
+ - karl@openmymind.net
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - lib/error_notifier/configuration.rb
59
+ - lib/error_notifier/rack.rb
60
+ - lib/error_notifier.rb
61
+ - license
62
+ - readme.markdown
63
+ homepage: http://github.com/karlseguin/error_notifier
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.21
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Post errors to an http server
90
+ test_files: []
91
+