chg: [brood:connectionTest] Correctly handles network exceptions
parent
7535cd2bdf
commit
b343c22f23
|
@ -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);
|
||||
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 => [
|
||||
|
|
|
@ -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'])
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue