From e41b31f330ffdeabf5768ef796711cceff97c2c1 Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Wed, 12 Aug 2026 19:40:22 +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. --- src/Client.cs | 2 +- tests/ErrorHandlingTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.cs b/src/Client.cs index 5cd6bf4..cdf7e9c 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -737,7 +737,7 @@ private GetStreamApiException BuildApiException(HttpResponseMessage response, st else { // Body cannot be parsed as APIError. - message = "failed to parse error response"; + message = $"failed to parse error response: unexpected server response code {statusCode}"; code = 0; exceptionFields = new Dictionary(); unrecoverable = false; diff --git a/tests/ErrorHandlingTests.cs b/tests/ErrorHandlingTests.cs index d06a05e..164e8df 100644 --- a/tests/ErrorHandlingTests.cs +++ b/tests/ErrorHandlingTests.cs @@ -263,7 +263,7 @@ await client.MakeRequestAsync( "GET", "/anything", null, null, null)); Assert.That(ex!.StatusCode, Is.EqualTo(500)); Assert.That(ex.Code, Is.EqualTo(0)); - Assert.That(ex.Message, Is.EqualTo("failed to parse error response")); + Assert.That(ex.Message, Is.EqualTo("failed to parse error response: unexpected server response code 500")); Assert.That(ex.RawResponseBody, Is.EqualTo("oops")); Assert.That(ex.ExceptionFields.Count, Is.EqualTo(0)); }