@senrab you need a try catch wrapper. Do you have it?
foreach ($listsToCheck->get() as $listToCheck) {
try{
$response = Http::get($listToCheck->url);
} catch (\Exception $e)
{
// handle the exception
}
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I am using the new(-ish) HTTP Client, something like this $response = Http::get($listToCheck->url);
I've actually stripped it back from $response = Http::retry(3, 500)->timeout(10)->get($listToCheck->url);
I am trying to catch the exception and store it in the DB. So if I run my code with $response = Http::get($listToCheck->url);to an URL that doesn't exist, I am getting a Illuminate\Http\Client\ConnectionException error thrown and the console command exits with this exception
cURL error 6: Could not resolve host: this.is.a.forced.fail.com
however I can't seem to catch that error and continue the code to insert the error into the DB
The docs say $response->throw();
Here's the code
foreach ($listsToCheck->get() as $listToCheck) {
$response = Http::get($listToCheck->url);
$response->throw();
dd('here');
...
All I see is the exception, I don't get the dd.
What am I missing?
Please or to participate in this conversation.