BUGFIX: curl errors were not catched

This commit is contained in:
Jeroen De Meerleer 2021-09-21 09:37:22 +02:00
parent 05d4c65fe2
commit 3438201b18
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
1 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,7 @@ namespace JeroenED\Webcron\Repository;
use DateTime;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use JeroenED\Framework\Repository;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Net\SSH2;
@ -136,10 +137,17 @@ class Job extends Repository
$url = $job['data']['url'];
$options['http_errors'] = false;
$options['auth'] = !empty($job['data']['basicauth-username']) ? [$job['data']['basicauth-username'], $job['data']['basicauth-password']] : NULL;
$res = $client->request('GET', $url, $options);
$return['exitcode'] = $res->getStatusCode();
$return['output'] = $res->getBody();
$return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']);
try {
$res = $client->request('GET', $url, $options);
$return['exitcode'] = $res->getStatusCode();
$return['output'] = $res->getBody();
$return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']);
} catch(RequestException $exception) {
$return['exitcode'] = $exception->getCode();
$return['output'] = $exception->getMessage();
$return['failed'] = true;
}
return $return;
}