From 8c4c75d83a935284c96b0bdcf548fae33dc66352 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Wed, 8 Jun 2022 11:51:52 +0200 Subject: [PATCH] fix: [localTools:action] Catch error if local tool's action returned unexpected data --- src/Controller/LocalToolsController.php | 5 ++++ .../genericElements/SingleViews/child.php | 30 +++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Controller/LocalToolsController.php b/src/Controller/LocalToolsController.php index baf8995..be7a4c2 100644 --- a/src/Controller/LocalToolsController.php +++ b/src/Controller/LocalToolsController.php @@ -6,6 +6,8 @@ use App\Controller\AppController; use Cake\Utility\Hash; use Cake\Utility\Text; use \Cake\Database\Expression\QueryExpression; +use Cake\Http\Exception\NotFoundException; +use Cake\Http\Exception\MethodNotAllowedException; class LocalToolsController extends AppController { @@ -110,6 +112,9 @@ class LocalToolsController extends AppController $actionDetails = $this->LocalTools->getActionDetails($actionName); $params['connection'] = $connection; $results = $this->LocalTools->action($this->ACL->getUser()['id'], $connection->connector, $actionName, $params, $this->request); + if (empty($results)) { + throw new MethodNotAllowedException(__('Could not execute the requested action.')); + } if (!empty($results['redirect'])) { $this->redirect($results['redirect']); } diff --git a/templates/element/genericElements/SingleViews/child.php b/templates/element/genericElements/SingleViews/child.php index dfac81c..ca982e3 100644 --- a/templates/element/genericElements/SingleViews/child.php +++ b/templates/element/genericElements/SingleViews/child.php @@ -39,24 +39,22 @@ var url = $('#view-child-body-').data('content-url'); var loadon = $('#view-child-body-').data('load-on'); if (loadon === 'ready') { - $.ajax({ - success:function (data, textStatus) { - $('#view-child-body-').html(data); - }, - type: "get", - cache: false, - url: url, - }); + AJAXApi.quickFetchURL(url, {}) + .then((html) => { + $('#view-child-body-').html(html); + }) + .catch((err) => { + $('#view-child-body-').text(err.message); + }) } else { $('#view-child-').on('hidden.bs.collapse', function () { - $.ajax({ - success:function (data, textStatus) { - $('#view-child-body-').html(data); - }, - type: "get", - cache: false, - url: url, - }); + AJAXApi.quickFetchURL(url, {}) + .then((html) => { + $('#view-child-body-').html(html); + }) + .catch((err) => { + $('#view-child-body-').text(err.message); + }) }) } });