action_network_rest 1.1.0 → 2.0.1
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/.ruby-version +1 -1
- data/CHANGELOG.md +14 -1
- data/lib/action_network_rest/response/raise_error.rb +54 -19
- data/lib/action_network_rest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1390448bae36f5af6554e8ff05b9e149c331cd59dc5eca35c2da1e300e80225
|
|
4
|
+
data.tar.gz: 8902d13dd62c3a801f07e599810d7969bb9bd4c1097d642c3c2a5e45b4b36414
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d74e20b22928d755fad1252d3626861d489ae2855866626e6f2769c4477107f213fde987bfb19132165f3ec469798a79790a4bab99e8790e434f78e93fa01f7
|
|
7
|
+
data.tar.gz: d5bf569a923e87ebe163496462bce1ba10c213f655cafe61b5b59344d60746be616413ddff1848b30a8b17bf420ba40c8e5761fd4b8bb42d39a0eaeae5cb396d
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.0.
|
|
1
|
+
4.0.10
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
### Other Changes
|
|
6
|
+
- Added a new error class UnexpectedResponseFormat, as a direct subclass of StandardError (not ServerError, as the request may already have been processed and shouldn't be retried). A 2xx response whose body isn't JSON (for example an HTML error or maintenance page) now raises it instead of returning a raw String that callers fail to index with a confusing TypeError or NoMethodError.
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-06-30
|
|
9
|
+
|
|
10
|
+
### Breaking Changes
|
|
11
|
+
- When a response has a 403 status, now raises AuthorizationError. (Previously, ResponseError was raised in this case.)
|
|
12
|
+
|
|
13
|
+
### Other Changes
|
|
14
|
+
- Added a new error class ServerError, as a subclass of ResponseError. 5xx response statuses now raise this more specific type of error.
|
|
15
|
+
|
|
3
16
|
## [1.1.0] - 2026-02-11
|
|
4
17
|
|
|
5
18
|
### Breaking Changes
|
|
6
19
|
- 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.
|
|
20
|
+
- Dropped support for Ruby versions older than 3.3. Officially supported versions are Ruby 3.3, 3.4, and 4.0.
|
|
@@ -3,34 +3,58 @@
|
|
|
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
|
|
9
|
-
|
|
10
|
-
if (
|
|
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
|
|
8
|
+
raise error_class_for(status_code, response), error_message(response) if (400...600).cover?(status_code)
|
|
9
|
+
raise UnexpectedResponseFormat, unexpected_format_message(response) if unparsed_body?(response)
|
|
26
10
|
end
|
|
27
|
-
# rubocop:enable Style/GuardClause
|
|
28
11
|
|
|
29
12
|
def error_message(response)
|
|
30
13
|
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} \n\n #{response[:body]}"
|
|
31
14
|
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# The JSON middleware only parses JSON content types, so a success status
|
|
19
|
+
# carrying anything else (e.g. an HTML maintenance page) arrives as a raw
|
|
20
|
+
# String that callers would otherwise index as if it were a Hash.
|
|
21
|
+
def unparsed_body?(response)
|
|
22
|
+
body = response[:body]
|
|
23
|
+
body.is_a?(String) && !body.strip.empty? && !content_type(response).match?(/\bjson\b/)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def unexpected_format_message(response)
|
|
27
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]} with non-JSON " \
|
|
28
|
+
"content-type #{content_type(response).inspect} \n\n #{response[:body][0, 500]}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def content_type(response)
|
|
32
|
+
(response[:response_headers] || {})['content-type'].to_s
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def error_class_for(status_code, response)
|
|
36
|
+
case status_code
|
|
37
|
+
when 400 then bad_request_error_class(response)
|
|
38
|
+
when 403 then AuthorizationError
|
|
39
|
+
when 404 then NotFoundError
|
|
40
|
+
when 429 then TooManyRequests
|
|
41
|
+
when 500..599 then ServerError
|
|
42
|
+
else ResponseError
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def bad_request_error_class(response)
|
|
47
|
+
return ResponseError unless response[:body].include?('error')
|
|
48
|
+
|
|
49
|
+
# A few specific 400 messages map to a dedicated exception; any other
|
|
50
|
+
# 400 still raises the generic ResponseError.
|
|
51
|
+
body_error = JSON.parse(response[:body])['error']
|
|
52
|
+
body_error == 'You must specify a valid person id' ? MustSpecifyValidPersonId : ResponseError
|
|
53
|
+
end
|
|
32
54
|
end
|
|
33
55
|
|
|
56
|
+
class AuthorizationError < StandardError; end
|
|
57
|
+
|
|
34
58
|
class MissingActionNetworkId < StandardError; end
|
|
35
59
|
|
|
36
60
|
class MustSpecifyValidPersonId < StandardError; end
|
|
@@ -39,6 +63,17 @@ module ActionNetworkRest
|
|
|
39
63
|
|
|
40
64
|
class ResponseError < StandardError; end
|
|
41
65
|
|
|
66
|
+
# Raised for 5xx responses. Subclasses ResponseError so existing rescues
|
|
67
|
+
# continue to catch server errors while allowing callers to distinguish
|
|
68
|
+
# transient server-side failures (worth retrying) from client errors.
|
|
69
|
+
class ServerError < ResponseError; end
|
|
70
|
+
|
|
71
|
+
# Raised when a success response has a body that isn't JSON, which happens
|
|
72
|
+
# when Action Network serves an error or maintenance page with a 2xx status.
|
|
73
|
+
# Deliberately not a ServerError: the request may already have been
|
|
74
|
+
# processed, so it shouldn't be treated as safe to retry.
|
|
75
|
+
class UnexpectedResponseFormat < StandardError; end
|
|
76
|
+
|
|
42
77
|
class TooManyRequests < StandardError; end
|
|
43
78
|
|
|
44
79
|
class UsedAllRequestTries < StandardError; end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: action_network_rest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Grey Moore
|
|
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
116
116
|
- !ruby/object:Gem::Version
|
|
117
117
|
version: '0'
|
|
118
118
|
requirements: []
|
|
119
|
-
rubygems_version: 4.0.
|
|
119
|
+
rubygems_version: 4.0.20
|
|
120
120
|
specification_version: 4
|
|
121
121
|
summary: Ruby client for interacting with the ActionNetwork REST API
|
|
122
122
|
test_files: []
|