I use Privoxy in CURL queries for different sites.
$ch = curl_init($url);
...
curl_setopt($ch, CURLOPT_PROXY, "localhost:8118");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
...
$result = curl_exec($ch);
Sometimes, if the site is not available, I get one of the Privoxy html templates displayed in the browser, usually it is /privoxy/templates/forwarding-failed at 503 error or /privoxy/templates/no-server-data at 502.
I would like to be able to handle these errors myself after receiving $result = curl_exec($ch);
as with normal CURL requests, without using Privoxy.
But I do not know how in Privoxy in the settings you can disable the connection and display of these error templates. Please tell me how you can solve this problem.
I used to be able to disable the output of the /privoxy/templates/blocked template using edits in the default.action and user.action files, but I did not find such settings there to disable the 502 or 503 error templates.
You can add the CURLOPT_FAILONERROR option to your CURL request to prevent CURL from returning the response content for HTTP error status codes (e.g., 502, 503) and instead handle them yourself.
If the HTTP server returns an error code of 400 or greater. This means that if the server returns a status code of 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), or anything else in the 400 range, the request will be aborted and the curl_exec() function will return FALSE.