frontend_rescue 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2ced1a4be7ab52073b8406376cfdaac662b2814
4
+ data.tar.gz: da28ed7391db65902d5287fd28b10087c094e01c
5
+ SHA512:
6
+ metadata.gz: be65b4db96136789ebb756a43bcad79258b6d3740a50eaa34494243061f4337fc3c9f72effcdaf42f355989a336613453e040c9378d7d46c819799d9e4c600cb
7
+ data.tar.gz: 351e679c08cdb0b9d43c01a5614fc402f0f21a8748547d81b4489acda559f25e33759960b8c58a991d4c27dc24dff38e6c3649ec1240b8ae017e406edc9818cd
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in frontend_rescue.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jim Durand
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ #### Frontend Rescue
2
+
3
+ frontend_rescue provides a backend endpoint for your frontend JavaScript application to send errors to when they’re caught.
4
+
5
+ This makes it easier to integrate your frontend stack traces to your backend analytics.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'frontend_rescue'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install frontend_rescue
22
+
23
+ ## Backend Usage
24
+
25
+ #### Rails
26
+
27
+ Rails.application.configure do
28
+ config.middleware.use ClientErrorHandler::Middleware, paths: ['/frontend-error']
29
+ end
30
+
31
+ #### Options
32
+
33
+ **status_code**
34
+
35
+ By default, frontend_rescue will respond with a ```500 (Server Error)```.
36
+
37
+ You can override this value with any HTTP status code you like :
38
+
39
+ config.middleware.use ClientErrorHandler::Middleware, paths: ['/frontend-error'],
40
+ status_code: 200
41
+
42
+ **silent**
43
+
44
+ By default, frontend_rescue will output the frontend error to the logs.
45
+
46
+ You can pass in ```silent: true```, frontend errors are not logged. You will likely use this option when passing a block.
47
+
48
+ **&block**
49
+
50
+ You can pass in a block to frontend_rescue and it will be called and passed a FrontendRescue::Error and a Rack::Request :
51
+
52
+ config.middleware.use ClientErrorHandler::Middleware, paths: ['/frontend-error'],
53
+ status_code: 200,
54
+ silent: true do |error, request|
55
+ NewRelic::Agent.notice_error(error)
56
+ end
57
+
58
+
59
+ #### Sinatra
60
+
61
+ use ClientErrorHandler::Middleware, paths: ['/frontend-error']
62
+
63
+ With the options described above.
64
+
65
+ ## Frontend Usage
66
+
67
+ Ideally you should catch all JavaScript errors and **post** them to your endpoint. Frontend frameworks like ember.js make this easy.
68
+
69
+ Ember example :
70
+
71
+ Ember.onerror = function(error) {
72
+ Ember.$.ajax('/frontend-error', {
73
+ type: 'POST',
74
+ data: {
75
+ name: 'My App',
76
+ user_agent: navigator.userAgent,
77
+ message: error.message,
78
+ stack: error.stack
79
+ }
80
+ });
81
+ };
82
+
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it ( https://github.com/[my-github-username]/frontend_rescue/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
91
+
92
+ ## TODO
93
+
94
+ 1. Tests...
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'frontend_rescue/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "frontend_rescue"
8
+ spec.version = FrontendRescue::VERSION
9
+ spec.authors = ["Jim Durand"]
10
+ spec.email = ["me@jdurand.com"]
11
+ spec.summary = "Provides a backend endpoint for your frontend JavaScript application to send errors to when they’re caught"
12
+ spec.description = "Provides a backend endpoint for your frontend JavaScript application to send errors to when they’re caught. This makes it easier to integrate your frontend stack traces to your backend analytics."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,17 @@
1
+ module FrontendRescue
2
+ class Error < StandardError
3
+ def initialize(name, user_agent, message, trace)
4
+ @trace = trace.split("\n") if trace.is_a? String
5
+ @user_agent = user_agent
6
+ super "Uncaught #{name} Error: #{message}"
7
+ end
8
+
9
+ def backtrace
10
+ ["User Agent: #{user_agent}"] + @trace
11
+ end
12
+
13
+ def user_agent
14
+ @user_agent
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ module FrontendRescue
2
+ class Middleware
3
+ def initialize(app, opts, &block)
4
+ @app = app
5
+ @opts = opts
6
+ @block = block
7
+ end
8
+
9
+ def call(env)
10
+ if env['REQUEST_METHOD'] == 'POST' && @opts[:paths].include?(env['PATH_INFO'])
11
+ handle_error Rack::Request.new(env)
12
+ else
13
+ @app.call(env)
14
+ end
15
+ end
16
+
17
+ private
18
+ def handle_error(request)
19
+ error = FrontendRescue::Error.new request.params['name'],
20
+ request.params['user_agent'],
21
+ request.params['message'],
22
+ request.params['stack']
23
+
24
+ request.env['rack.errors'].puts "Processing #{error.class}" unless @opts[:silent]
25
+
26
+ if @block
27
+ @block.call(error, request)
28
+ end
29
+
30
+ unless @opts[:silent]
31
+ request.env['rack.errors'].puts error.message
32
+ request.env['rack.errors'].puts error.backtrace.join("\n")
33
+ request.env['rack.errors'].flush
34
+ end
35
+
36
+ code = @opts[:status_code] || 500
37
+ request.env['rack.errors'].puts "Completed #{code} OK"
38
+ [code, {}, []]
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module FrontendRescue
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "frontend_rescue/version"
2
+ require "frontend_rescue/error"
3
+ require "frontend_rescue/middleware"
4
+
5
+ module FrontendRescue
6
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frontend_rescue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jim Durand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Provides a backend endpoint for your frontend JavaScript application
42
+ to send errors to when they’re caught. This makes it easier to integrate your frontend
43
+ stack traces to your backend analytics.
44
+ email:
45
+ - me@jdurand.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - frontend_rescue.gemspec
56
+ - lib/frontend_rescue.rb
57
+ - lib/frontend_rescue/error.rb
58
+ - lib/frontend_rescue/middleware.rb
59
+ - lib/frontend_rescue/version.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Provides a backend endpoint for your frontend JavaScript application to send
84
+ errors to when they’re caught
85
+ test_files: []
86
+ has_rdoc: