From ec77a0ab15f77fb888da94bd54a3d0e8296fd838 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:18:05 -0700 Subject: [PATCH] fix: rescue JSON::ParserError in response hook JSON::ParseError is not defined by the json gem, so a subscribed response hook and a non-JSON body raised NameError instead of falling back to the raw body. --- CHANGELOG.md | 4 ++++ lib/easypost/http_client.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fafa201c..ae3a68b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## Next Release + +- Fixes response hooks raising `NameError` when an HTTP body is not JSON + ## v7.8.0 (2026-10-27) - Removes the deprecated, unusable `add_credit_card` function diff --git a/lib/easypost/http_client.rb b/lib/easypost/http_client.rb index 5d0c9c61..7160faba 100644 --- a/lib/easypost/http_client.rb +++ b/lib/easypost/http_client.rb @@ -76,7 +76,7 @@ def request( if response.is_a?(Net::HTTPResponse) response_body = begin JSON.parse(response.body) - rescue JSON::ParseError + rescue JSON::ParserError response.body end response_context.merge!(