rescue_registry 0.2.0 → 0.2.5
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/CHANGELOG.md +23 -0
- data/README.md +1 -0
- data/lib/rescue_registry.rb +13 -0
- data/lib/rescue_registry/exception_handler.rb +2 -1
- data/lib/rescue_registry/exceptions_app.rb +1 -6
- data/lib/rescue_registry/rails_test_helpers.rb +42 -0
- data/lib/rescue_registry/version.rb +1 -1
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237133f9678393d12439ef50317b1671632606d3d35a7b5f658cf4eab3083bbc
|
4
|
+
data.tar.gz: ffac90b369e7b345fd74de72db7178f420b9577ca30e26d1b8427cf2e58049e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43d1e9755b0333d69646594e28e6caef2219e02b9a18d466fd8bee0b204d4fefdc817628d958899abe8e6391327a5a9f131889ea0ee44ac611e778d5a1f3d70c
|
7
|
+
data.tar.gz: 54dcad7d3ad63eec2dd5c752cafff76ff248832093603f45e1c0c959e10b8e62dcc9102e1823a163b5c6452022ab6fc3f2ed8ac5267cbcc52290916092329b6f
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
---
|
9
9
|
|
10
|
+
## [0.2.5] - 2021-03-09
|
11
|
+
### Added
|
12
|
+
- `code` can now be provided as an argument to `register_exception` - #29 (thanks @amaierhofer)
|
13
|
+
|
14
|
+
## [0.2.4] - 2021-01-22
|
15
|
+
### Fixed
|
16
|
+
- Support Ruby 3 (thanks @zvkemp and @ef4)
|
17
|
+
|
18
|
+
## [0.2.3] - 2020-09-01
|
19
|
+
### Fixed
|
20
|
+
- Properly handle exceptions for invalid format types - #25 (thanks @shanet)
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
- Lower minimum Ruby requirement to 2.3 (thanks @elDub)
|
24
|
+
|
25
|
+
## [0.2.2] - 2019-06-13
|
26
|
+
### Changed
|
27
|
+
- Lower minimum Ruby requirement to 2.3 (thanks @elDub)
|
28
|
+
|
29
|
+
## [0.2.1] - 2019-05-22
|
30
|
+
### Added
|
31
|
+
- RescueRegistry::RailsTestingHelpers provides some helpers for easier testing in Rails applications.
|
32
|
+
|
10
33
|
## [0.2.0] - 2019-05-21
|
11
34
|
### Added
|
12
35
|
- Support for non-Rails applications.
|
data/README.md
CHANGED
@@ -58,6 +58,7 @@ class MyController < ActionController::Base
|
|
58
58
|
register_exception MetaProcError, meta: -> (e) { { class_name: e.class.name.upcase } }
|
59
59
|
register_exception CustomHandlerError, handler: CustomErrorHandler
|
60
60
|
register_exception RailsError, status: 403, handler: RescueRegistry::RailsExceptionHandler
|
61
|
+
register_exception CustomStatusError, status: 422, code: :name_invalid
|
61
62
|
end
|
62
63
|
```
|
63
64
|
|
data/lib/rescue_registry.rb
CHANGED
@@ -9,6 +9,7 @@ module RescueRegistry
|
|
9
9
|
autoload :ExceptionsApp, "rescue_registry/exceptions_app"
|
10
10
|
autoload :ExceptionHandler, "rescue_registry/exception_handler"
|
11
11
|
autoload :RailsExceptionHandler, "rescue_registry/exception_handler"
|
12
|
+
autoload :RailsTestHelpers, "rescue_registry/rails_test_helpers"
|
12
13
|
autoload :Registry, "rescue_registry/registry"
|
13
14
|
autoload :ResetContext, "rescue_registry/reset_context"
|
14
15
|
autoload :ShowExceptions, "rescue_registry/show_exceptions"
|
@@ -45,6 +46,18 @@ module RescueRegistry
|
|
45
46
|
context.rescue_registry.public_send(method, *args)
|
46
47
|
end
|
47
48
|
end
|
49
|
+
|
50
|
+
# the Module#ruby2_keywords is added starting at ruby 2.7. It lets us mark
|
51
|
+
# these methods as using ruby2-style keyword argument semantics. This will
|
52
|
+
# keep them working correctly on ruby3, and clears a deprecation that
|
53
|
+
# otherwise fires in 2.7+.
|
54
|
+
if respond_to?(:ruby2_keywords, true)
|
55
|
+
class << self
|
56
|
+
REGISTRY_METHODS.each do |method|
|
57
|
+
ruby2_keywords(method)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
48
61
|
end
|
49
62
|
|
50
63
|
ActiveSupport.on_load(:before_initialize) do
|
@@ -21,6 +21,7 @@ module RescueRegistry
|
|
21
21
|
end
|
22
22
|
|
23
23
|
@meta = options[:meta]
|
24
|
+
@code = options[:code]
|
24
25
|
|
25
26
|
# TODO: Warn about unrecognized options
|
26
27
|
end
|
@@ -29,7 +30,7 @@ module RescueRegistry
|
|
29
30
|
alias_method :status_code, :status
|
30
31
|
|
31
32
|
def error_code
|
32
|
-
error_code_from_status
|
33
|
+
@code.presence || error_code_from_status
|
33
34
|
end
|
34
35
|
|
35
36
|
def title
|
@@ -9,12 +9,7 @@ module RescueRegistry
|
|
9
9
|
exception = request.get_header "action_dispatch.exception"
|
10
10
|
|
11
11
|
if RescueRegistry.handles_exception?(exception)
|
12
|
-
|
13
|
-
content_type = request.formats.first
|
14
|
-
rescue Mime::Type::InvalidMimeType
|
15
|
-
content_type = Mime[:text]
|
16
|
-
end
|
17
|
-
|
12
|
+
content_type = request.formats.first || Mime[:text]
|
18
13
|
response = RescueRegistry.response_for_public(content_type, exception)
|
19
14
|
end
|
20
15
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RescueRegistry
|
2
|
+
# Helpers to improve the ease of testing error handling in Rails tests.
|
3
|
+
# These are not actually specific to RescueRegistry, but will certainly be useful for it.
|
4
|
+
module RailsTestHelpers
|
5
|
+
def handle_request_exceptions(handle = true, &block)
|
6
|
+
set_action_dispatch_property(:show_exceptions, handle, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def handle_request_exceptions?
|
10
|
+
Rails.application.config.action_dispatch.show_exceptions
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_detailed_exceptions(show = true, &block)
|
14
|
+
set_action_dispatch_property(:show_detailed_exceptions, show, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_detailed_exceptions?
|
18
|
+
Rails.application.config.action_dispatch.show_detailed_exceptions
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def set_action_dispatch_property(key, value)
|
24
|
+
if block_given?
|
25
|
+
original_value = Rails.application.config.action_dispatch.send(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
Rails.application.config.action_dispatch.send("#{key}=", value)
|
29
|
+
# Also set this since it may have been cached
|
30
|
+
Rails.application.env_config["action_dispatch.#{key}"] = value
|
31
|
+
|
32
|
+
if block_given?
|
33
|
+
begin
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
Rails.application.env_config["action_dispatch.#{key}"] = original_value
|
37
|
+
Rails.application.config.action_dispatch.send("#{key}=", original_value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rescue_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Wagenet
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.9'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- peter.wagenet@gmail.com
|
86
86
|
executables: []
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/rescue_registry/controller.rb
|
101
101
|
- lib/rescue_registry/exception_handler.rb
|
102
102
|
- lib/rescue_registry/exceptions_app.rb
|
103
|
+
- lib/rescue_registry/rails_test_helpers.rb
|
103
104
|
- lib/rescue_registry/railtie.rb
|
104
105
|
- lib/rescue_registry/registry.rb
|
105
106
|
- lib/rescue_registry/reset_context.rb
|
@@ -113,23 +114,26 @@ metadata:
|
|
113
114
|
bug_tracker_uri: https://github.com/wagenet/rescue_registry/issues
|
114
115
|
changelog_uri: https://github.com/wagenet/rescue_registry/CHANGELOG.md
|
115
116
|
source_code_uri: https://github.com/wagenet/rescue_registry
|
116
|
-
post_install_message:
|
117
|
+
post_install_message:
|
117
118
|
rdoc_options: []
|
118
119
|
require_paths:
|
119
120
|
- lib
|
120
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
122
|
requirements:
|
122
|
-
- - "
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.3'
|
126
|
+
- - "<"
|
123
127
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
128
|
+
version: '3.1'
|
125
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
130
|
requirements:
|
127
131
|
- - ">="
|
128
132
|
- !ruby/object:Gem::Version
|
129
133
|
version: '0'
|
130
134
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
135
|
+
rubygems_version: 3.2.3
|
136
|
+
signing_key:
|
133
137
|
specification_version: 4
|
134
138
|
summary: Registry for Rails Exceptions
|
135
139
|
test_files: []
|