From 7b738f46b03e43eaa35a9bce993e6d713184bd2f Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Wed, 12 Aug 2026 19:40:27 +0200 Subject: [PATCH] fix: name the HTTP status when the error body is not JSON An unparseable error body produced the message "failed to parse error response", which hid the HTTP status. The message now appends the status to that text, so prefix matching and substring matching both keep working. The status code, the raw response body and the parse cause do not change. --- lib/getstream_ruby/error_mapping.rb | 2 +- lib/getstream_ruby/errors.rb | 3 ++- spec/errors_spec.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/getstream_ruby/error_mapping.rb b/lib/getstream_ruby/error_mapping.rb index ab71a30..bf70f43 100644 --- a/lib/getstream_ruby/error_mapping.rb +++ b/lib/getstream_ruby/error_mapping.rb @@ -31,7 +31,7 @@ def raise_api_error(response) end raise ApiError.new( - message: 'failed to parse error response', + message: "failed to parse error response: unexpected server response code #{response.status}", status_code: response.status, code: 0, exception_fields: {}, diff --git a/lib/getstream_ruby/errors.rb b/lib/getstream_ruby/errors.rb index 9e13cc1..e95cc40 100644 --- a/lib/getstream_ruby/errors.rb +++ b/lib/getstream_ruby/errors.rb @@ -13,7 +13,8 @@ class ConfigurationError < StreamError; end # Raised on any HTTP 4xx/5xx response. Also raised when an HTTP response is # received but its body is not a parseable `APIError` envelope, with `code = 0` - # and `message = "failed to parse error response"`. + # and `message = "failed to parse error response: unexpected server response + # code "`. class ApiError < StreamError attr_reader :status_code, :code, :exception_fields, :unrecoverable, diff --git a/spec/errors_spec.rb b/spec/errors_spec.rb index 0391fe5..e8ccacb 100644 --- a/spec/errors_spec.rb +++ b/spec/errors_spec.rb @@ -307,7 +307,7 @@ expect(err.status_code).to eq(500) expect(err.code).to eq(0) - expect(err.message).to eq('failed to parse error response') + expect(err.message).to eq('failed to parse error response: unexpected server response code 500') expect(err.raw_response_body).to eq('oops') end