Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Illuminate/Http/Client/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/Integration/Foundation/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
}
}

Loading