action_network_rest 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c17dbaa0d2bb98ff782e6935fd6f2be4487615ed22723cf852c2e38a423e390
4
- data.tar.gz: 075b4fd3bc99898d124a0d8126257eabb5034c149795b06f52e45c18b555d597
3
+ metadata.gz: b1390448bae36f5af6554e8ff05b9e149c331cd59dc5eca35c2da1e300e80225
4
+ data.tar.gz: 8902d13dd62c3a801f07e599810d7969bb9bd4c1097d642c3c2a5e45b4b36414
5
5
  SHA512:
6
- metadata.gz: ffff94abab45bedc8a263ab2aff6614390c065ceea0d098ba3f517d738733dd831e6030d460e9162e1fbb3cd52230d4c2bda159923439d9165b2ca49f7626b23
7
- data.tar.gz: c69a7c00e2a31a22171df146af077f34a18ba710c7cfc6cae61beea2c06778e9d4328635a00825d84536ccf7c0df1e064fdfb7dc5b6d0c902cb5208a4b43c1e5
6
+ metadata.gz: 3d74e20b22928d755fad1252d3626861d489ae2855866626e6f2769c4477107f213fde987bfb19132165f3ec469798a79790a4bab99e8790e434f78e93fa01f7
7
+ data.tar.gz: d5bf569a923e87ebe163496462bce1ba10c213f655cafe61b5b59344d60746be616413ddff1848b30a8b17bf420ba40c8e5761fd4b8bb42d39a0eaeae5cb396d
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.1
1
+ 4.0.10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## [2.0.0] - 2026-06-30
4
9
 
5
10
  ### Breaking Changes
@@ -5,9 +5,8 @@ module ActionNetworkRest
5
5
  class RaiseError < Faraday::Middleware
6
6
  def on_complete(response)
7
7
  status_code = response[:status].to_i
8
- return unless (400...600).cover?(status_code)
9
-
10
- raise error_class_for(status_code, response), error_message(response)
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)
11
10
  end
12
11
 
13
12
  def error_message(response)
@@ -16,6 +15,23 @@ module ActionNetworkRest
16
15
 
17
16
  private
18
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
+
19
35
  def error_class_for(status_code, response)
20
36
  case status_code
21
37
  when 400 then bad_request_error_class(response)
@@ -52,6 +68,12 @@ module ActionNetworkRest
52
68
  # transient server-side failures (worth retrying) from client errors.
53
69
  class ServerError < ResponseError; end
54
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
+
55
77
  class TooManyRequests < StandardError; end
56
78
 
57
79
  class UsedAllRequestTries < StandardError; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionNetworkRest
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
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: 2.0.0
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.3
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: []