How to handle errors by sending a GET request using curl?

curl_setopt($curl, CURLOPT_URL, 'http://api.test/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_FAILONERROR, true); $content = curl_exec($curl); curl_close($curl); if($content){//проверяем что нету ошибок (ПОПЫТКА проверки) var_dump("Нету ошибок"); } 

    1 answer 1

    You just need to get the server response code curl_getinfo($curl,CURLINFO_HTTP_CODE) if the code is 200 or 304 then everything is fine. if 404 or 405 is already an error. in general, the idea is to just handle the server response codes.