catching cURL errors with PHP/Laravel
cURL error 6: Could not resolve host laravel
Now this is cool and all, but I don't actually want it to return a cURL error and stop my program.
I'd prefer something like this:
if (guzzle client timed out) {
do this
} else {
do that
}
/Use the inbuilt Laravel Exception class.
Solution:
<?php
namespace App\Http\Controllers;
use Exception;
class MyController extends Controller
{
public function index()
{
try
{
$crawler = $goutteClient->request('GET', 'https://www.google.com');
}
catch(Exception $e)
{
logger()->error('Goutte client error ' . $e->getMessage());
}
}
}
source : https://stackoverflow.com/questions/57579993/catching-curl-errors-with-php-laravel