rescue_registry 0.2.1 → 0.3.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/CHANGELOG.md +24 -0
- data/README.md +1 -0
- data/lib/rescue_registry.rb +12 -0
- data/lib/rescue_registry/exception_handler.rb +15 -8
- data/lib/rescue_registry/exceptions_app.rb +1 -6
- data/lib/rescue_registry/version.rb +1 -1
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1680176387616a079a616679ca436f7e1a81ff266c1a6d8d574caa71e6ccab7
|
4
|
+
data.tar.gz: 329c59744d4fc5eddb2a1d91fc3049df660966a54b13625b667e4085b59daeb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f174ee373dc0352d366bb4e4ad6deedd95185600e904db85fe472622765e0726e6c07678de7f28c002cf5e39279725bc3400f5db105acb81254a20acb0945acb
|
7
|
+
data.tar.gz: a3f82a0a1b907baf038cb274a0fb8d7fbb4198e49dc9f5d6b49aee417b782c22dedd03cb17bf8d314f6507f6faf40cb7dc0928871d1a44d3af81f9692b9305e2
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
---
|
9
9
|
|
10
|
+
## [0.3.0] - 2021-05-11
|
11
|
+
### Changed
|
12
|
+
- For better JSONAPI spec compliance, errors payloads will not include the `details` key when value is `null`.
|
13
|
+
- Error payloads will not include the `meta` key when value is an empty object.
|
14
|
+
|
15
|
+
## [0.2.5] - 2021-03-09
|
16
|
+
### Added
|
17
|
+
- `code` can now be provided as an argument to `register_exception` - #29 (thanks @amaierhofer)
|
18
|
+
|
19
|
+
## [0.2.4] - 2021-01-22
|
20
|
+
### Fixed
|
21
|
+
- Support Ruby 3 (thanks @zvkemp and @ef4)
|
22
|
+
|
23
|
+
## [0.2.3] - 2020-09-01
|
24
|
+
### Fixed
|
25
|
+
- Properly handle exceptions for invalid format types - #25 (thanks @shanet)
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
- Lower minimum Ruby requirement to 2.3 (thanks @elDub)
|
29
|
+
|
30
|
+
## [0.2.2] - 2019-06-13
|
31
|
+
### Changed
|
32
|
+
- Lower minimum Ruby requirement to 2.3 (thanks @elDub)
|
33
|
+
|
10
34
|
## [0.2.1] - 2019-05-22
|
11
35
|
### Added
|
12
36
|
- RescueRegistry::RailsTestingHelpers provides some helpers for easier testing in 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
@@ -46,6 +46,18 @@ module RescueRegistry
|
|
46
46
|
context.rescue_registry.public_send(method, *args)
|
47
47
|
end
|
48
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
|
49
61
|
end
|
50
62
|
|
51
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
|
@@ -74,14 +75,20 @@ module RescueRegistry
|
|
74
75
|
)
|
75
76
|
end
|
76
77
|
|
78
|
+
error_payload = {
|
79
|
+
code: error_code,
|
80
|
+
status: status_code.to_s,
|
81
|
+
title: title
|
82
|
+
}
|
83
|
+
|
84
|
+
if (d = detail)
|
85
|
+
error_payload[:detail] = d
|
86
|
+
end
|
87
|
+
|
88
|
+
error_payload[:meta] = payload_meta if payload_meta.any?
|
89
|
+
|
77
90
|
{
|
78
|
-
errors: [
|
79
|
-
code: error_code,
|
80
|
-
status: status_code.to_s,
|
81
|
-
title: title,
|
82
|
-
detail: detail,
|
83
|
-
meta: payload_meta
|
84
|
-
]
|
91
|
+
errors: [error_payload]
|
85
92
|
}
|
86
93
|
end
|
87
94
|
|
@@ -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
|
|
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.
|
4
|
+
version: 0.3.0
|
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-05-11 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: []
|
@@ -114,23 +114,26 @@ metadata:
|
|
114
114
|
bug_tracker_uri: https://github.com/wagenet/rescue_registry/issues
|
115
115
|
changelog_uri: https://github.com/wagenet/rescue_registry/CHANGELOG.md
|
116
116
|
source_code_uri: https://github.com/wagenet/rescue_registry
|
117
|
-
post_install_message:
|
117
|
+
post_install_message:
|
118
118
|
rdoc_options: []
|
119
119
|
require_paths:
|
120
120
|
- lib
|
121
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.3'
|
126
|
+
- - "<"
|
124
127
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
128
|
+
version: '3.1'
|
126
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
130
|
requirements:
|
128
131
|
- - ">="
|
129
132
|
- !ruby/object:Gem::Version
|
130
133
|
version: '0'
|
131
134
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
135
|
+
rubygems_version: 3.2.15
|
136
|
+
signing_key:
|
134
137
|
specification_version: 4
|
135
138
|
summary: Registry for Rails Exceptions
|
136
139
|
test_files: []
|