openstax_rescue_from 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -10
- data/lib/generators/openstax/rescue_from/install/templates/rescue_from.rb +70 -9
- data/lib/openstax/rescue_from.rb +7 -31
- data/lib/openstax/rescue_from/configuration.rb +8 -19
- data/lib/openstax/rescue_from/engine.rb +10 -6
- data/lib/openstax/rescue_from/version.rb +1 -1
- data/openstax_rescue_from.gemspec +1 -1
- metadata +11 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2cc06b01e38970a2435d345c200406e28dcc557
|
4
|
+
data.tar.gz: d2645ad9a8e7178c0b4e6776058833ffaec26e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deca2133ec2fe2f98e217b8c3ae0cd5a9426b6fbc0bda854c643257db6c297415784cf6736b167f0c65177c42cf75f73c663a2e3abb494a01d1b0b2e419f60ce
|
7
|
+
data.tar.gz: 4bf1841f1c6e61c94933f2128cc1d2929786634a557e519c20b7fb7ad8fe46eb53d965c73e9b97a2e5df9a0355c04571b03119bb2b2ea41bfa21b1754de15207
|
data/README.md
CHANGED
@@ -89,18 +89,82 @@ OpenStax::RescueFrom.configure do |config|
|
|
89
89
|
Rails.application.config.consider_all_requests_local
|
90
90
|
|
91
91
|
config.app_name = ENV['APP_NAME']
|
92
|
-
|
92
|
+
# Can be a name, or a web/email address. See 'View helper' below
|
93
93
|
config.contact_name = ENV['EXCEPTION_CONTACT_NAME']
|
94
|
-
# can be a name, or a web/email address. See 'View helper' below
|
95
94
|
|
96
|
-
|
95
|
+
# To use ExceptionNotifier add `gem 'exception_notification'` to your Gemfile and then:
|
96
|
+
# config.notify_proc = ->(proxy, controller) do
|
97
|
+
# ExceptionNotifier.notify_exception(
|
98
|
+
# proxy.exception,
|
99
|
+
# env: controller.request.env,
|
100
|
+
# data: {
|
101
|
+
# error_id: proxy.error_id,
|
102
|
+
# class: proxy.name,
|
103
|
+
# message: proxy.message,
|
104
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
105
|
+
# cause: proxy.cause,
|
106
|
+
# dns_name: resolve_ip(controller.request.remote_ip),
|
107
|
+
# extras: proxy.extras
|
108
|
+
# },
|
109
|
+
# sections: %w(data request session environment backtrace)
|
110
|
+
# )
|
111
|
+
# end
|
112
|
+
# config.notify_background_proc = ->(proxy) do
|
113
|
+
# ExceptionNotifier.notify_exception(
|
114
|
+
# proxy.exception,
|
115
|
+
# data: {
|
116
|
+
# error_id: proxy.error_id,
|
117
|
+
# class: proxy.name,
|
118
|
+
# message: proxy.message,
|
119
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
120
|
+
# cause: proxy.cause,
|
121
|
+
# extras: proxy.extras
|
122
|
+
# },
|
123
|
+
# sections: %w(data environment backtrace)
|
124
|
+
# )
|
125
|
+
# end
|
126
|
+
# config.notify_rack_middleware = ExceptionNotification::Rack
|
127
|
+
# config.notify_rack_middleware_options = {
|
128
|
+
# email: {
|
129
|
+
# email_prefix: "[#{config.app_name}] (#{ENV['APP_ENV']}) ",
|
130
|
+
# sender_address: ENV['EXCEPTION_SENDER'],
|
131
|
+
# exception_recipients: ENV['EXCEPTION_RECIPIENTS']
|
132
|
+
# }
|
133
|
+
# }
|
134
|
+
# URL generation errors are caused by bad routes, for example, and should not be ignored
|
135
|
+
# ExceptionNotifier.ignored_exceptions.delete("ActionController::UrlGenerationError")
|
136
|
+
|
137
|
+
# To use Raven (Sentry) add `gem 'sentry-raven', require: 'raven/base'` to your Gemfile and then:
|
138
|
+
# config.notify_proc = -> do |proxy, controller|
|
139
|
+
# extra = {
|
140
|
+
# error_id: proxy.error_id,
|
141
|
+
# class: proxy.name,
|
142
|
+
# message: proxy.message,
|
143
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
144
|
+
# cause: proxy.cause,
|
145
|
+
# dns_name: resolve_ip(controller.request.remote_ip)
|
146
|
+
# }
|
147
|
+
# extra.merge!(proxy.extras) if proxy.extras.is_a? Hash
|
148
|
+
#
|
149
|
+
# Raven.capture_exception(proxy.exception, extra: extra)
|
150
|
+
# end
|
151
|
+
# config.notify_background_proc = -> do |proxy|
|
152
|
+
# extra = {
|
153
|
+
# error_id: proxy.error_id,
|
154
|
+
# class: proxy.name,
|
155
|
+
# message: proxy.message,
|
156
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
157
|
+
# cause: proxy.cause
|
158
|
+
# }
|
159
|
+
# extra.merge!(proxy.extras) if proxy.extras.is_a? Hash
|
160
|
+
#
|
161
|
+
# Raven.capture_exception(proxy.exception, extra: extra)
|
162
|
+
# end
|
163
|
+
# require 'raven/integrations/rack'
|
164
|
+
# config.notify_rack_middleware = Raven::Rack
|
97
165
|
|
98
166
|
config.html_error_template_path = 'errors/any'
|
99
167
|
config.html_error_template_layout_name = 'application'
|
100
|
-
|
101
|
-
config.email_prefix = "[#{app_name}] (#{app_env}) "
|
102
|
-
config.sender_address = ENV['EXCEPTION_SENDER']
|
103
|
-
config.exception_recipients = ENV['EXCEPTION_RECIPIENTS']
|
104
168
|
end
|
105
169
|
|
106
170
|
# Exceptions in controllers might be reraised or not depending on the settings above
|
@@ -108,9 +172,6 @@ ActionController::Base.use_openstax_exception_rescue
|
|
108
172
|
|
109
173
|
# RescueFrom always reraises background exceptions so that the background job may properly fail
|
110
174
|
ActiveJob::Base.use_openstax_exception_rescue
|
111
|
-
|
112
|
-
# URL generation errors are caused by bad routes, for example, and should not be ignored
|
113
|
-
ExceptionNotifier.ignored_exceptions.delete("ActionController::UrlGenerationError")
|
114
175
|
```
|
115
176
|
|
116
177
|
## Controller hook
|
@@ -8,17 +8,81 @@ OpenStax::RescueFrom.configure do |config|
|
|
8
8
|
)
|
9
9
|
|
10
10
|
# config.app_name = ENV['APP_NAME']
|
11
|
-
# config.app_env = ENV['APP_ENV']
|
12
11
|
# config.contact_name = ENV['EXCEPTION_CONTACT_NAME']
|
13
12
|
|
14
|
-
#
|
13
|
+
# To use ExceptionNotifier add `gem 'exception_notification'` to your Gemfile and then:
|
14
|
+
# config.notify_proc = ->(proxy, controller) do
|
15
|
+
# ExceptionNotifier.notify_exception(
|
16
|
+
# proxy.exception,
|
17
|
+
# env: controller.request.env,
|
18
|
+
# data: {
|
19
|
+
# error_id: proxy.error_id,
|
20
|
+
# class: proxy.name,
|
21
|
+
# message: proxy.message,
|
22
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
23
|
+
# cause: proxy.cause,
|
24
|
+
# dns_name: resolve_ip(controller.request.remote_ip),
|
25
|
+
# extras: proxy.extras
|
26
|
+
# },
|
27
|
+
# sections: %w(data request session environment backtrace)
|
28
|
+
# )
|
29
|
+
# end
|
30
|
+
# config.notify_background_proc = ->(proxy) do
|
31
|
+
# ExceptionNotifier.notify_exception(
|
32
|
+
# proxy.exception,
|
33
|
+
# data: {
|
34
|
+
# error_id: proxy.error_id,
|
35
|
+
# class: proxy.name,
|
36
|
+
# message: proxy.message,
|
37
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
38
|
+
# cause: proxy.cause,
|
39
|
+
# extras: proxy.extras
|
40
|
+
# },
|
41
|
+
# sections: %w(data environment backtrace)
|
42
|
+
# )
|
43
|
+
# end
|
44
|
+
# config.notify_rack_middleware = ExceptionNotification::Rack
|
45
|
+
# config.notify_rack_middleware_options = {
|
46
|
+
# email: {
|
47
|
+
# email_prefix: "[#{config.app_name}] (#{ENV['APP_ENV']}) ",
|
48
|
+
# sender_address: ENV['EXCEPTION_SENDER'],
|
49
|
+
# exception_recipients: ENV['EXCEPTION_RECIPIENTS']
|
50
|
+
# }
|
51
|
+
# }
|
52
|
+
# URL generation errors are caused by bad routes, for example, and should not be ignored
|
53
|
+
# ExceptionNotifier.ignored_exceptions.delete("ActionController::UrlGenerationError")
|
54
|
+
|
55
|
+
# To use Raven (Sentry) add `gem 'sentry-raven', require: 'raven/base'` to your Gemfile and then:
|
56
|
+
# config.notify_proc = -> do |proxy, controller|
|
57
|
+
# extra = {
|
58
|
+
# error_id: proxy.error_id,
|
59
|
+
# class: proxy.name,
|
60
|
+
# message: proxy.message,
|
61
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
62
|
+
# cause: proxy.cause,
|
63
|
+
# dns_name: resolve_ip(controller.request.remote_ip)
|
64
|
+
# }
|
65
|
+
# extra.merge!(proxy.extras) if proxy.extras.is_a? Hash
|
66
|
+
#
|
67
|
+
# Raven.capture_exception(proxy.exception, extra: extra)
|
68
|
+
# end
|
69
|
+
# config.notify_background_proc = -> do |proxy|
|
70
|
+
# extra = {
|
71
|
+
# error_id: proxy.error_id,
|
72
|
+
# class: proxy.name,
|
73
|
+
# message: proxy.message,
|
74
|
+
# first_line_of_backtrace: proxy.first_backtrace_line,
|
75
|
+
# cause: proxy.cause
|
76
|
+
# }
|
77
|
+
# extra.merge!(proxy.extras) if proxy.extras.is_a? Hash
|
78
|
+
#
|
79
|
+
# Raven.capture_exception(proxy.exception, extra: extra)
|
80
|
+
# end
|
81
|
+
# require 'raven/integrations/rack'
|
82
|
+
# config.notify_rack_middleware = Raven::Rack
|
15
83
|
|
16
84
|
# config.html_error_template_path = 'errors/any'
|
17
85
|
# config.html_error_template_layout_name = 'application'
|
18
|
-
|
19
|
-
# config.email_prefix = "[#{app_name}] (#{app_env}) "
|
20
|
-
# config.sender_address = ENV['EXCEPTION_SENDER']
|
21
|
-
# config.exception_recipients = ENV['EXCEPTION_RECIPIENTS']
|
22
86
|
end
|
23
87
|
|
24
88
|
# Exceptions in controllers might be reraised or not depending on the settings above
|
@@ -27,9 +91,6 @@ ActionController::Base.use_openstax_exception_rescue
|
|
27
91
|
# RescueFrom always reraises background exceptions so that the background job may properly fail
|
28
92
|
ActiveJob::Base.use_openstax_exception_rescue
|
29
93
|
|
30
|
-
# URL generation errors are caused by bad routes, for example, and should not be ignored
|
31
|
-
ExceptionNotifier.ignored_exceptions.delete("ActionController::UrlGenerationError")
|
32
|
-
|
33
94
|
# OpenStax::RescueFrom.translate_status_codes(
|
34
95
|
# internal_server_error: "Sorry, #{OpenStax::RescueFrom.configuration.app_name} had some unexpected trouble with your request.",
|
35
96
|
# not_found: 'We could not find the requested information.',
|
data/lib/openstax/rescue_from.rb
CHANGED
@@ -150,40 +150,16 @@ module OpenStax
|
|
150
150
|
logger.record_system_error!('A background job exception occurred')
|
151
151
|
end
|
152
152
|
|
153
|
-
def send_notifying_exceptions(proxy,
|
154
|
-
if notifies_for?(proxy.name)
|
155
|
-
|
156
|
-
|
157
|
-
env: listener.request.env,
|
158
|
-
data: {
|
159
|
-
error_id: proxy.error_id,
|
160
|
-
class: proxy.name,
|
161
|
-
message: proxy.message,
|
162
|
-
first_line_of_backtrace: proxy.first_backtrace_line,
|
163
|
-
cause: proxy.cause,
|
164
|
-
dns_name: resolve_ip(listener.request.remote_ip),
|
165
|
-
extras: proxy.extras
|
166
|
-
},
|
167
|
-
sections: %w(data request session environment backtrace)
|
168
|
-
)
|
169
|
-
end
|
153
|
+
def send_notifying_exceptions(proxy, controller)
|
154
|
+
return if !configuration.notify_exceptions || !notifies_for?(proxy.name)
|
155
|
+
|
156
|
+
instance_exec(proxy, controller, &configuration.notify_proc)
|
170
157
|
end
|
171
158
|
|
172
159
|
def send_notifying_background_exceptions(proxy)
|
173
|
-
if notifies_for?(proxy.name)
|
174
|
-
|
175
|
-
|
176
|
-
data: {
|
177
|
-
error_id: proxy.error_id,
|
178
|
-
class: proxy.name,
|
179
|
-
message: proxy.message,
|
180
|
-
first_line_of_backtrace: proxy.first_backtrace_line,
|
181
|
-
cause: proxy.cause,
|
182
|
-
extras: proxy.extras
|
183
|
-
},
|
184
|
-
sections: %w(data environment backtrace)
|
185
|
-
)
|
186
|
-
end
|
160
|
+
return if !configuration.notify_background_exceptions || !notifies_for?(proxy.name)
|
161
|
+
|
162
|
+
instance_exec(proxy, &configuration.notify_background_proc)
|
187
163
|
end
|
188
164
|
|
189
165
|
def finish_exception_rescue(proxy, listener)
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require 'exception_notification'
|
2
|
-
|
3
1
|
module OpenStax
|
4
2
|
module RescueFrom
|
5
3
|
class Configuration
|
6
4
|
|
7
|
-
attr_accessor :raise_exceptions, :raise_background_exceptions, :
|
8
|
-
:
|
9
|
-
:
|
5
|
+
attr_accessor :raise_exceptions, :raise_background_exceptions, :notify_exceptions,
|
6
|
+
:notify_proc, :notify_background_exceptions, :notify_background_proc,
|
7
|
+
:notify_rack_middleware, :notify_rack_middleware_options,
|
8
|
+
:html_error_template_path, :html_error_template_layout_name, :app_name
|
10
9
|
|
11
10
|
attr_writer :contact_name
|
12
11
|
|
@@ -21,25 +20,15 @@ module OpenStax
|
|
21
20
|
)
|
22
21
|
|
23
22
|
@app_name = ENV['APP_NAME']
|
24
|
-
@app_env = ENV['APP_ENV']
|
25
23
|
@contact_name = ENV['EXCEPTION_CONTACT_NAME']
|
26
24
|
|
27
|
-
@
|
25
|
+
@notify_exceptions = true
|
26
|
+
@notify_proc = ->(proxy, controller) {}
|
27
|
+
@notify_background_exceptions = true
|
28
|
+
@notify_background_proc = ->(proxy) {}
|
28
29
|
|
29
30
|
@html_error_template_path = 'errors/any'
|
30
31
|
@html_error_template_layout_name = 'application'
|
31
|
-
|
32
|
-
@sender_address = ENV['EXCEPTION_SENDER']
|
33
|
-
@exception_recipients = ENV['EXCEPTION_RECIPIENTS']
|
34
|
-
end
|
35
|
-
|
36
|
-
def email_prefix
|
37
|
-
return(@email_prefix) if defined?(@email_prefix) && !@email_prefix.blank?
|
38
|
-
|
39
|
-
name = app_name.blank? ? nil : "[#{app_name}]"
|
40
|
-
env = app_env.blank? ? nil : "(#{app_env}) "
|
41
|
-
|
42
|
-
@email_prefix = [name, env].compact.join(' ')
|
43
32
|
end
|
44
33
|
end
|
45
34
|
end
|
@@ -9,12 +9,16 @@ module OpenStax
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
initializer "openstax.rescue_from.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
initializer "openstax.rescue_from.use_rack_middleware" do
|
13
|
+
middleware = OpenStax::RescueFrom.configuration.notify_rack_middleware
|
14
|
+
next if middleware.blank?
|
15
|
+
|
16
|
+
options = OpenStax::RescueFrom.configuration.notify_rack_middleware_options
|
17
|
+
if options.nil?
|
18
|
+
Rails.application.config.middleware.insert_before 0, middleware
|
19
|
+
else
|
20
|
+
Rails.application.config.middleware.insert_before 0, middleware, options
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
initializer "openstax.rescue_from.pre_register_exceptions" do
|
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.required_ruby_version = '>= 2.0'
|
22
22
|
|
23
23
|
spec.add_dependency "rails", '>= 3.1', '< 6.0'
|
24
|
-
spec.add_dependency "exception_notification", '>= 4.1', '< 5.0'
|
25
24
|
|
26
25
|
spec.add_development_dependency "bundler"
|
27
26
|
spec.add_development_dependency "pg"
|
28
27
|
spec.add_development_dependency "rspec-rails"
|
29
28
|
spec.add_development_dependency "rails-controller-testing"
|
30
29
|
spec.add_development_dependency "database_cleaner"
|
30
|
+
spec.add_development_dependency "exception_notification"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstax_rescue_from
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Slavinsky
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -32,27 +32,21 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6.0'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
35
|
+
name: bundler
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '5.0'
|
44
|
-
type: :runtime
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
45
42
|
prerelease: false
|
46
43
|
version_requirements: !ruby/object:Gem::Requirement
|
47
44
|
requirements:
|
48
45
|
- - ">="
|
49
46
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
51
|
-
- - "<"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '5.0'
|
47
|
+
version: '0'
|
54
48
|
- !ruby/object:Gem::Dependency
|
55
|
-
name:
|
49
|
+
name: pg
|
56
50
|
requirement: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
52
|
- - ">="
|
@@ -66,7 +60,7 @@ dependencies:
|
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '0'
|
68
62
|
- !ruby/object:Gem::Dependency
|
69
|
-
name:
|
63
|
+
name: rspec-rails
|
70
64
|
requirement: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
66
|
- - ">="
|
@@ -80,7 +74,7 @@ dependencies:
|
|
80
74
|
- !ruby/object:Gem::Version
|
81
75
|
version: '0'
|
82
76
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
77
|
+
name: rails-controller-testing
|
84
78
|
requirement: !ruby/object:Gem::Requirement
|
85
79
|
requirements:
|
86
80
|
- - ">="
|
@@ -94,7 +88,7 @@ dependencies:
|
|
94
88
|
- !ruby/object:Gem::Version
|
95
89
|
version: '0'
|
96
90
|
- !ruby/object:Gem::Dependency
|
97
|
-
name:
|
91
|
+
name: database_cleaner
|
98
92
|
requirement: !ruby/object:Gem::Requirement
|
99
93
|
requirements:
|
100
94
|
- - ">="
|
@@ -108,7 +102,7 @@ dependencies:
|
|
108
102
|
- !ruby/object:Gem::Version
|
109
103
|
version: '0'
|
110
104
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
105
|
+
name: exception_notification
|
112
106
|
requirement: !ruby/object:Gem::Requirement
|
113
107
|
requirements:
|
114
108
|
- - ">="
|