diff --git a/lib/Http/Client/Middleware/HttpClientLoggerMiddleware.php b/lib/Http/Client/Middleware/HttpClientLoggerMiddleware.php index ce3db81..c46e785 100644 --- a/lib/Http/Client/Middleware/HttpClientLoggerMiddleware.php +++ b/lib/Http/Client/Middleware/HttpClientLoggerMiddleware.php @@ -270,7 +270,9 @@ function ($reason) use ($request, $reqHeaders, $reqId) { if ($reason instanceof \Throwable) { throw $reason; } - throw new \RuntimeException('HTTP request rejected: ' . (string)$reason); + throw new \RuntimeException( + 'HTTP request rejected: ' . (is_object($reason) ? get_class($reason) : (string)$reason) + ); } ); }; diff --git a/lib/Http/Client/Middleware/LogWriter.php b/lib/Http/Client/Middleware/LogWriter.php index 082b8ba..5ad6a20 100644 --- a/lib/Http/Client/Middleware/LogWriter.php +++ b/lib/Http/Client/Middleware/LogWriter.php @@ -28,7 +28,12 @@ public static function write( LoggerInterface $logger, ): void { if (in_array($format, ['json', 'both'], true)) { - self::append($jsonFile, json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL, $logger); + // Remote servers can send headers with broken UTF-8; substitute + // those bytes instead of losing the whole entry. + $json = json_encode($entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE); + if ($json !== false) { + self::append($jsonFile, $json . PHP_EOL, $logger); + } } if (in_array($format, ['plain', 'both'], true)) { self::append($plainFile, $plainLine, $logger);