chg: [brood:connectionTest] Correctly handles network exceptions
parent
4f8b663b87
commit
eef09f44c4
|
@ -9,6 +9,7 @@ use Cake\Core\Configure;
|
||||||
use Cake\Http\Client;
|
use Cake\Http\Client;
|
||||||
use Cake\Http\Client\Response;
|
use Cake\Http\Client\Response;
|
||||||
use Cake\Http\Exception\NotFoundException;
|
use Cake\Http\Exception\NotFoundException;
|
||||||
|
use Cake\Http\Client\Exception\NetworkException;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use Cake\Error\Debugger;
|
use Cake\Error\Debugger;
|
||||||
|
|
||||||
|
@ -69,7 +70,14 @@ class BroodsTable extends AppTable
|
||||||
{
|
{
|
||||||
$brood = $this->find()->where(['id' => $id])->first();
|
$brood = $this->find()->where(['id' => $id])->first();
|
||||||
$start = microtime(true);
|
$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)));
|
$ping = ((int)(100 * (microtime(true) - $start)));
|
||||||
$errors = [
|
$errors = [
|
||||||
403 => [
|
403 => [
|
||||||
|
|
|
@ -55,8 +55,10 @@ function attachTestConnectionResultHtml(result, $container) {
|
||||||
$testResultDiv.append(getKVHtml('Internal error', result, ['text-danger fw-bold']))
|
$testResultDiv.append(getKVHtml('Internal error', result, ['text-danger fw-bold']))
|
||||||
} else {
|
} else {
|
||||||
if (result['error']) {
|
if (result['error']) {
|
||||||
|
if (result['ping']) {
|
||||||
|
$testResultDiv.append('Status', 'OK', ['text-danger'], `${result['ping']} ms`);
|
||||||
|
}
|
||||||
$testResultDiv.append(
|
$testResultDiv.append(
|
||||||
getKVHtml('Status', 'OK', ['text-danger'], `${result['ping']} ms`),
|
|
||||||
getKVHtml('Status', `Error: ${result['error']}`, ['text-danger']),
|
getKVHtml('Status', `Error: ${result['error']}`, ['text-danger']),
|
||||||
getKVHtml('Reason', result['reason'], ['text-danger'])
|
getKVHtml('Reason', result['reason'], ['text-danger'])
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue