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 15:02:00 +02:00
parent ba8158f35e
commit 0fab645ce8
No known key found for this signature in database
GPG Key ID: 3B23D1B3498D7641

View File

@ -28,8 +28,13 @@ 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) {
if(method_exists($e, 'getResponse')) {
$res = $e->getResponse();
$hasresponse = true;
} else {
$hasresponse = false; $hasresponse = false;
} }
}
if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') { if (isset($c['http']['data']) && $c['http']['data'] == 'responsebody') {
$output = $res->getBody()->getContents(); $output = $res->getBody()->getContents();