From fd5ef00ca8b832203e7ab11e8f0b0431ab6f1899 Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Wed, 12 Aug 2026 19:40:06 +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/Http/GuzzleHttpClient.php | 2 +- tests/Exceptions/ErrorHandlingTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/GuzzleHttpClient.php b/src/Http/GuzzleHttpClient.php index 8bee107..0fe803b 100644 --- a/src/Http/GuzzleHttpClient.php +++ b/src/Http/GuzzleHttpClient.php @@ -467,7 +467,7 @@ private function buildApiException( if (!$parsedEnvelope) { // HTTP layer succeeded, body is unparseable as APIError. - $message = 'failed to parse error response'; + $message = sprintf('failed to parse error response: unexpected server response code %d', $statusCode); } if ($statusCode === 429) { diff --git a/tests/Exceptions/ErrorHandlingTest.php b/tests/Exceptions/ErrorHandlingTest.php index 2116157..3680122 100644 --- a/tests/Exceptions/ErrorHandlingTest.php +++ b/tests/Exceptions/ErrorHandlingTest.php @@ -106,7 +106,7 @@ public function unparseableErrorResponseFallsBackToSentinelMessage(): void self::assertSame(500, $e->getStatusCode()); self::assertSame(500, $e->getCode(), 'getCode() returns HTTP status (back-compat)'); self::assertSame(0, $e->getApiErrorCode(), 'APIError.code is 0 on unparseable body'); - self::assertSame('failed to parse error response', $e->getMessage()); + self::assertSame('failed to parse error response: unexpected server response code 500', $e->getMessage()); self::assertSame('<<>>', $e->getRawResponseBody()); self::assertNotNull($e->getPrevious(), 'cause chain must point to the JSON parse error'); self::assertInstanceOf(\JsonException::class, $e->getPrevious());