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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1917a4b296e7224c3241742af15375a1c07f8ac6ec45131aaa9e6422b1dc0564
4
- data.tar.gz: ed2cc9463b6b0f5a9621ecf1dde0873fa475ab88e9b15de6630fa0640dabc0c9
3
+ metadata.gz: 6c17dbaa0d2bb98ff782e6935fd6f2be4487615ed22723cf852c2e38a423e390
4
+ data.tar.gz: 075b4fd3bc99898d124a0d8126257eabb5034c149795b06f52e45c18b555d597
5
5
  SHA512:
6
- metadata.gz: 3607a4d26767b60bc1615f7e7ce080b9f5b208461faf8c2c3707f8014fb41074eed92600340c8ff12a5204f64505a05cf3a99a395af74bb239d7f2e02ca6f374
7
- data.tar.gz: 7226aaf245a03715d265ed29ac04147ecbef67244bb905d63d667a90256c53d28b886475b3cf69c684b137f6e4f183864156896c26ef1127deed6e3392e4025d
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
- if (400...600).cover? status_code
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionNetworkRest
4
- VERSION = '1.1.0'
4
+ VERSION = '2.0.0'
5
5
  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: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grey Moore