Skip to content

Commit 585e4e0

Browse files
authored
fix: name the HTTP status when the error body is not JSON (#58)
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.
1 parent 226cec3 commit 585e4e0

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/Http/GuzzleHttpClient.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private function buildApiException(
467467

468468
if (!$parsedEnvelope) {
469469
// HTTP layer succeeded, body is unparseable as APIError.
470-
$message = 'failed to parse error response';
470+
$message = sprintf('failed to parse error response: unexpected server response code %d', $statusCode);
471471
}
472472

473473
if ($statusCode === 429) {

‎tests/Exceptions/ErrorHandlingTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function unparseableErrorResponseFallsBackToSentinelMessage(): void
106106
self::assertSame(500, $e->getStatusCode());
107107
self::assertSame(500, $e->getCode(), 'getCode() returns HTTP status (back-compat)');
108108
self::assertSame(0, $e->getApiErrorCode(), 'APIError.code is 0 on unparseable body');
109-
self::assertSame('failed to parse error response', $e->getMessage());
109+
self::assertSame('failed to parse error response: unexpected server response code 500', $e->getMessage());
110110
self::assertSame('<<<not json>>>', $e->getRawResponseBody());
111111
self::assertNotNull($e->getPrevious(), 'cause chain must point to the JSON parse error');
112112
self::assertInstanceOf(\JsonException::class, $e->getPrevious());

0 commit comments

Comments
 (0)