diff --git a/src/Illuminate/Http/Client/RequestException.php b/src/Illuminate/Http/Client/RequestException.php index 1bdd38503c8a..fc6641f3786c 100644 --- a/src/Illuminate/Http/Client/RequestException.php +++ b/src/Illuminate/Http/Client/RequestException.php @@ -83,17 +83,17 @@ public static function dontTruncate() /** * Prepare the exception message. * - * @return void + * @return bool */ - public function report(): void + public function report() { - if ($this->hasBeenSummarized) { - return; - } + if (! $this->hasBeenSummarized) { + $this->message = $this->prepareMessage($this->response); - $this->message = $this->prepareMessage($this->response); + $this->hasBeenSummarized = true; + } - $this->hasBeenSummarized = true; + return false; } /** diff --git a/tests/Integration/Foundation/ExceptionHandlerTest.php b/tests/Integration/Foundation/ExceptionHandlerTest.php index b4a52ecee635..2dac2d9658d9 100644 --- a/tests/Integration/Foundation/ExceptionHandlerTest.php +++ b/tests/Integration/Foundation/ExceptionHandlerTest.php @@ -9,10 +9,14 @@ use Illuminate\Contracts\Debug\ShouldntReport; use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract; use Illuminate\Contracts\Support\Responsable; +use Illuminate\Http\Client\RequestException; use Illuminate\Http\JsonResponse; use Illuminate\Routing\ResponseFactory; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; +use Monolog\Handler\TestHandler; use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\DataProvider; use Symfony\Component\Process\PhpProcess; @@ -281,4 +285,29 @@ public function json($data = [], $status = 200, array $headers = [], $options = 'success' => false, ]); } + + public function test_it_reports_request_exceptions() + { + config(['logging.default' => 'test_log']); + config(['logging.channels.test_log' => [ + 'driver' => 'monolog', + 'handler' => TestHandler::class, + ]]); + Log::setDefaultDriver('test_log'); + Http::fake([ + '*' => Http::response('a really long message is being returned', status:500), + ]); + + RequestException::truncateAt(8); + try { + Http::throw()->get('http://laravel.test'); + } catch (RequestException $requestException) { + report($requestException); + } + + $recordedLogs = Log::getLogger()->getHandlers()[0]->getRecords(); + $this->assertCount(1, $recordedLogs); + $this->assertStringContainsString('a really (truncated...)', $recordedLogs[0]['message']); + } } +