rollbar-user_informer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 295ea0d558c68c4b213479cda787b90d53d23ac0
4
+ data.tar.gz: 7c3f1aa90c3edcb7fece17f6bf20a696ba13928b
5
+ SHA512:
6
+ metadata.gz: b2d88391aa468131981222e3fb4108ca84d7ed3cfe315bcf7e08ee92c797057cc445e6ddee5c895726d20ccb53499058260202b72912c3c19e0131041516e5db
7
+ data.tar.gz: 28789f8f49b1fbec3e8c9247d6434cb4850d443632b1a94d1c2656df41781fdb05c123db148f0f66789d475adf869a5b5d5fdecb28bef161c1b7a220ba9976d2
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Ryan Gurney <ryan.a.gurney@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rollbar'
4
+
5
+ module Rollbar
6
+ module UserInformer
7
+ REQUEST_ENV_KEY = "rollbar.exception_uuid"
8
+ DEFAULT_PLACEHOLDER = "<!-- ROLLBAR ERROR -->"
9
+
10
+ class << self
11
+ attr_accessor :user_information
12
+ attr_accessor :user_information_placeholder
13
+ end
14
+
15
+ class Middleware
16
+ def initialize(app)
17
+ @app = app
18
+ end
19
+
20
+ def call(env)
21
+ status, headers, body = @app.call(env)
22
+ if (replacement = Rollbar::UserInformer.user_information) && (error_uuid = env[REQUEST_ENV_KEY])
23
+ replacement = replacement.gsub(/\{\{\s*error_uuid\s*\}\}/, error_uuid)
24
+ body = replace_placeholder(replacement, body, headers)
25
+ headers["Error-Id"] = error_uuid
26
+ end
27
+ [status, headers, body]
28
+ end
29
+
30
+ private
31
+
32
+ # - body interface is .each so we cannot use anything else
33
+ # - always call .close on the old body so it can get garbage collected if it is a File
34
+ def replace_placeholder(replacement, body, headers)
35
+ new_body = []
36
+ body.each do |chunk|
37
+ new_body << chunk.gsub(Rollbar::UserInformer.user_information_placeholder || DEFAULT_PLACEHOLDER, replacement)
38
+ end
39
+ headers["Content-Length"] = new_body.inject(0) { |sum, x| sum + x.bytesize }.to_s
40
+ new_body
41
+ ensure
42
+ body.close if body&.respond_to?(:close)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # Untested below this point. If changed test in example app
49
+ if defined?(::Rails::Railtie)
50
+ module Rollbar
51
+ module UserInformer
52
+ class Railtie < ::Rails::Railtie
53
+ initializer("rollbar.user_informer") do |app|
54
+ app.config.middleware.insert_before(
55
+ ActionDispatch::ShowExceptions,
56
+ Rollbar::UserInformer::Middleware
57
+ )
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Rollbar
3
+ module UserInformer
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rollbar-user_informer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Gurney
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rollbar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.15'
27
+ description:
28
+ email: ryan.a.gurney@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - MIT-LICENSE
34
+ - lib/rollbar/user_informer.rb
35
+ - lib/rollbar/user_informer/version.rb
36
+ homepage: https://github.com/ragurney/rollbar-user_informer
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.3.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.14
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: show exception ids on error pages for easier support
60
+ test_files: []