Refactor error handling for GuzzleException

- Refactored error handling to check for response in exception.
This commit is contained in:
Jeroen De Meerleer 2024-06-03 19:48:39 +02:00
parent aa1ee0cc11
commit aea6873ed8
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -28,7 +28,12 @@ if($_SERVER["REQUEST_URI"] == '/metrics' || php_sapi_name() == 'cli') {
$res = $client->request('GET', $c['http']['url'], $options); $res = $client->request('GET', $c['http']['url'], $options);
$hasresponse = true; $hasresponse = true;
} catch(GuzzleHttp\Exception\GuzzleException $e) { } catch(GuzzleHttp\Exception\GuzzleException $e) {
$hasresponse = false; if(method_exists($e, 'getResponse')) {
$res = $e->getResponse();
$hasresponse = true;
} else {
$hasresponse = false;
}
} }
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') { if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {