action_network_rest 1.1.0 → 2.0.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 +9 -1
- data/lib/action_network_rest/response/raise_error.rb +31 -18
- data/lib/action_network_rest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c17dbaa0d2bb98ff782e6935fd6f2be4487615ed22723cf852c2e38a423e390
|
|
4
|
+
data.tar.gz: 075b4fd3bc99898d124a0d8126257eabb5034c149795b06f52e45c18b555d597
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffff94abab45bedc8a263ab2aff6614390c065ceea0d098ba3f517d738733dd831e6030d460e9162e1fbb3cd52230d4c2bda159923439d9165b2ca49f7626b23
|
|
7
|
+
data.tar.gz: c69a7c00e2a31a22171df146af077f34a18ba710c7cfc6cae61beea2c06778e9d4328635a00825d84536ccf7c0df1e064fdfb7dc5b6d0c902cb5208a4b43c1e5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0] - 2026-06-30
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
- When a response has a 403 status, now raises AuthorizationError. (Previously, ResponseError was raised in this case.)
|
|
7
|
+
|
|
8
|
+
### Other Changes
|
|
9
|
+
- Added a new error class ServerError, as a subclass of ResponseError. 5xx response statuses now raise this more specific type of error.
|
|
10
|
+
|
|
3
11
|
## [1.1.0] - 2026-02-11
|
|
4
12
|
|
|
5
13
|
### Breaking Changes
|
|
6
14
|
- Now requires Faraday 2.x (previously supported Faraday 1.x)
|
|
7
|
-
- Dropped support for Ruby versions older than 3.3. Officially supported versions are Ruby 3.3, 3.4, and 4.0.
|
|
15
|
+
- Dropped support for Ruby versions older than 3.3. Officially supported versions are Ruby 3.3, 3.4, and 4.0.
|
|
@@ -3,34 +3,42 @@
|
|
|
3
3
|
module ActionNetworkRest
|
|
4
4
|
module Response
|
|
5
5
|
class RaiseError < Faraday::Middleware
|
|
6
|
-
# rubocop:disable Style/GuardClause
|
|
7
6
|
def on_complete(response)
|
|
8
7
|
status_code = response[:status].to_i
|
|
8
|
+
return unless (400...600).cover?(status_code)
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
if status_code == 400 && response[:body].include?('error')
|
|
12
|
-
error_hsh = JSON.parse(response[:body])
|
|
13
|
-
error_message = error_hsh['error']
|
|
14
|
-
|
|
15
|
-
if error_message == 'You must specify a valid person id'
|
|
16
|
-
raise MustSpecifyValidPersonId, error_message(response)
|
|
17
|
-
end
|
|
18
|
-
elsif status_code == 404
|
|
19
|
-
raise NotFoundError, error_message(response)
|
|
20
|
-
elsif status_code == 429
|
|
21
|
-
raise TooManyRequests, error_message(response)
|
|
22
|
-
else
|
|
23
|
-
raise ResponseError, error_message(response)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
10
|
+
raise error_class_for(status_code, response), error_message(response)
|
|
26
11
|
end
|
|
27
|
-
# rubocop:enable Style/GuardClause
|
|
28
12
|
|
|
29
13
|
def error_message(response)
|
|
30
14
|
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
|
|
31
15
|
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def error_class_for(status_code, response)
|
|
20
|
+
case status_code
|
|
21
|
+
when 400 then bad_request_error_class(response)
|
|
22
|
+
when 403 then AuthorizationError
|
|
23
|
+
when 404 then NotFoundError
|
|
24
|
+
when 429 then TooManyRequests
|
|
25
|
+
when 500..599 then ServerError
|
|
26
|
+
else ResponseError
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def bad_request_error_class(response)
|
|
31
|
+
return ResponseError unless response[:body].include?('error')
|
|
32
|
+
|
|
33
|
+
# A few specific 400 messages map to a dedicated exception; any other
|
|
34
|
+
# 400 still raises the generic ResponseError.
|
|
35
|
+
body_error = JSON.parse(response[:body])['error']
|
|
36
|
+
body_error == 'You must specify a valid person id' ? MustSpecifyValidPersonId : ResponseError
|
|
37
|
+
end
|
|
32
38
|
end
|
|
33
39
|
|
|
40
|
+
class AuthorizationError < StandardError; end
|
|
41
|
+
|
|
34
42
|
class MissingActionNetworkId < StandardError; end
|
|
35
43
|
|
|
36
44
|
class MustSpecifyValidPersonId < StandardError; end
|
|
@@ -39,6 +47,11 @@ module ActionNetworkRest
|
|
|
39
47
|
|
|
40
48
|
class ResponseError < StandardError; end
|
|
41
49
|
|
|
50
|
+
# Raised for 5xx responses. Subclasses ResponseError so existing rescues
|
|
51
|
+
# continue to catch server errors while allowing callers to distinguish
|
|
52
|
+
# transient server-side failures (worth retrying) from client errors.
|
|
53
|
+
class ServerError < ResponseError; end
|
|
54
|
+
|
|
42
55
|
class TooManyRequests < StandardError; end
|
|
43
56
|
|
|
44
57
|
class UsedAllRequestTries < StandardError; end
|