ndr_error 2.1.0 → 2.2.0
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 +4 -4
- data/README.md +5 -0
- data/lib/ndr_error.rb +1 -0
- data/lib/ndr_error/middleware/public_exceptions.rb +3 -34
- data/lib/ndr_error/recorder.rb +45 -0
- data/lib/ndr_error/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89b4e3b5c4c353c4451a663613117248484b70ca4765e88c234d0ef7fef257e1
|
4
|
+
data.tar.gz: f506e8f64cdfd4e24306c5859e3db30e8eb4ca0bc9c99a0e420b50c3582414a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba72752fa59c55f7a04fc15e57c9fae93c4df17a6eeb7918c18ae3ae466e2ee34a9578255d0d9a7c1d5a3bdadf5c14dd95c4db0dfbfc776b0cce63af10081f39
|
7
|
+
data.tar.gz: 2895abbd8d19f9a0868889437ead29029040f6e7f1ec601859c96f913953f41541bc172b958d21a2d1d3abcb62ac9755b12483cf884607af2b440ad88949fcdd
|
data/README.md
CHANGED
@@ -38,6 +38,11 @@ a Rack application that can be used as part of the Rails exception-handling midd
|
|
38
38
|
|
39
39
|
In the host application's `application.rb`, the following configuration can be added:
|
40
40
|
|
41
|
+
To log the error, but have the host application's routing respond:
|
42
|
+
```ruby
|
43
|
+
config.exceptions_app = NdrError::Recorder.new(self.routes)
|
44
|
+
```
|
45
|
+
or log the error, then serve error templates from `public/` (legacy):
|
41
46
|
```ruby
|
42
47
|
require 'ndr_error/middleware/public_exceptions'
|
43
48
|
# Configure the ActionDispatch::ShowExceptions middleware to use NdrError's exception logger:
|
data/lib/ndr_error.rb
CHANGED
@@ -1,40 +1,9 @@
|
|
1
1
|
module NdrError
|
2
2
|
module Middleware
|
3
3
|
# Middleware for logging exceptions, can be used as exception_app for Rails.
|
4
|
-
class PublicExceptions < ::
|
5
|
-
def
|
6
|
-
|
7
|
-
request = ActionDispatch::Request.new(env)
|
8
|
-
exception = env['action_dispatch.exception']
|
9
|
-
|
10
|
-
# "falsey" callback return value allows logging to be skipped
|
11
|
-
log_exception(request, exception) if run_exception_callback(request, exception)
|
12
|
-
end
|
13
|
-
|
14
|
-
super # Invoke the PublicExceptions behaviour
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def log_exception(request, exception)
|
20
|
-
parameters = NdrError.log_parameters.call(request)
|
21
|
-
_fingerprint, _log = NdrError.log(exception, parameters, request)
|
22
|
-
end
|
23
|
-
|
24
|
-
def run_exception_callback(request, exception)
|
25
|
-
NdrError.exception_app_callback.call(request, exception)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Unhandled exceptions with logging could terminate the web server!
|
29
|
-
def rescuing_everything
|
30
|
-
yield
|
31
|
-
rescue Exception => exception # rubocop:disable Lint/RescueException
|
32
|
-
# "Log the exception caused by logging an exception..."
|
33
|
-
Rails.logger.warn <<-MSG.strip_heredoc
|
34
|
-
NdrError failed to log an exception!
|
35
|
-
logging error class: #{exception.class}
|
36
|
-
logging error message: #{exception.message}
|
37
|
-
MSG
|
4
|
+
class PublicExceptions < NdrError::Recorder
|
5
|
+
def initialize(public_path)
|
6
|
+
super ::ActionDispatch::PublicExceptions.new(public_path)
|
38
7
|
end
|
39
8
|
end
|
40
9
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module NdrError
|
2
|
+
# Middleware for logging exceptions, can be used as exception_app for Rails.
|
3
|
+
class Recorder
|
4
|
+
# the parent_handler could be the host app's routes, or an instance
|
5
|
+
# of ActionDispatch::PublicExceptions, or any other middleware.
|
6
|
+
def initialize(parent_handler)
|
7
|
+
@parent_handler = parent_handler
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
rescuing_everything do
|
12
|
+
request = ActionDispatch::Request.new(env)
|
13
|
+
exception = env['action_dispatch.exception']
|
14
|
+
|
15
|
+
# "falsey" callback return value allows logging to be skipped
|
16
|
+
log_exception(request, exception) if run_exception_callback(request, exception)
|
17
|
+
end
|
18
|
+
|
19
|
+
@parent_handler.call(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def log_exception(request, exception)
|
25
|
+
parameters = NdrError.log_parameters.call(request)
|
26
|
+
_fingerprint, _log = NdrError.log(exception, parameters, request)
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_exception_callback(request, exception)
|
30
|
+
NdrError.exception_app_callback.call(request, exception)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Unhandled exceptions with logging could terminate the web server!
|
34
|
+
def rescuing_everything
|
35
|
+
yield
|
36
|
+
rescue Exception => exception # rubocop:disable Lint/RescueException
|
37
|
+
# "Log the exception caused by logging an exception..."
|
38
|
+
Rails.logger.warn <<-MSG.strip_heredoc
|
39
|
+
NdrError failed to log an exception!
|
40
|
+
logging error class: #{exception.class}
|
41
|
+
logging error message: #{exception.message}
|
42
|
+
MSG
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/ndr_error/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndr_error
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NCRS Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/ndr_error/fuzzing.rb
|
190
190
|
- lib/ndr_error/logging.rb
|
191
191
|
- lib/ndr_error/middleware/public_exceptions.rb
|
192
|
+
- lib/ndr_error/recorder.rb
|
192
193
|
- lib/ndr_error/uuid_builder.rb
|
193
194
|
- lib/ndr_error/version.rb
|
194
195
|
- lib/tasks/ndr_error_tasks.rake
|