chg: [brood:connectionTest] Correctly handles network exceptions

pull/93/head
Sami Mokaddem 2022-01-24 16:35:42 +01:00
parent 7535cd2bdf
commit b343c22f23
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 12 additions and 2 deletions

View File

@ -9,6 +9,7 @@ use Cake\Core\Configure;
use Cake\Http\Client;
use Cake\Http\Client\Response;
use Cake\Http\Exception\NotFoundException;
use Cake\Http\Client\Exception\NetworkException;
use Cake\ORM\TableRegistry;
use Cake\Error\Debugger;
@ -69,7 +70,14 @@ class BroodsTable extends AppTable
{
$brood = $this->find()->where(['id' => $id])->first();
$start = microtime(true);
$response = $this->HTTPClientGET('/instance/status.json', $brood);
try {
$response = $this->HTTPClientGET('/instance/status.json', $brood);
} catch (NetworkException $e) {
return [
'error' => __('Could not query status'),
'reason' => $e->getMessage(),
];
}
$ping = ((int)(100 * (microtime(true) - $start)));
$errors = [
403 => [

View File

@ -55,8 +55,10 @@ function attachTestConnectionResultHtml(result, $container) {
$testResultDiv.append(getKVHtml('Internal error', result, ['text-danger fw-bold']))
} else {
if (result['error']) {
if (result['ping']) {
$testResultDiv.append('Status', 'OK', ['text-danger'], `${result['ping']} ms`);
}
$testResultDiv.append(
getKVHtml('Status', 'OK', ['text-danger'], `${result['ping']} ms`),
getKVHtml('Status', `Error: ${result['error']}`, ['text-danger']),
getKVHtml('Reason', result['reason'], ['text-danger'])
)