diff options
author | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-11-04 15:50:30 +0300 |
---|---|---|
committer | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-11-04 15:50:30 +0300 |
commit | a307ff6a2c53ac8b9bc9df7b50c4ade19bc69248 (patch) | |
tree | 236af3ef8ed1cb0bba1bd6743165da11bbfe5c8e /ui | |
parent | dbcedde046368b7a88d9b5a90837b0b2c1420c51 (diff) |
..F....... [ZBXNEXT-7469] fixed page loading errors
Diffstat (limited to 'ui')
-rw-r--r-- | ui/include/classes/core/ZBase.php | 73 | ||||
-rw-r--r-- | ui/include/classes/mvc/CPageNotFoundException.php | 27 | ||||
-rw-r--r-- | ui/js/class.dashboard.js | 2 | ||||
-rw-r--r-- | ui/js/common.js | 20 |
4 files changed, 97 insertions, 25 deletions
diff --git a/ui/include/classes/core/ZBase.php b/ui/include/classes/core/ZBase.php index 264f188571c..055aacd38e8 100644 --- a/ui/include/classes/core/ZBase.php +++ b/ui/include/classes/core/ZBase.php @@ -562,7 +562,7 @@ class ZBase { try { if ($action_class === null) { - throw new Exception(_('Class not found.')); + throw new CPageNotFoundException(); } if (!class_exists($action_class)) { @@ -626,30 +626,13 @@ class ZBase { catch (CAccessDeniedException $e) { $this->denyPageAccess($router); } - catch (Exception $e) { - switch ($router->getLayout()) { - case 'layout.json': - case 'layout.widget': - echo (new CView('layout.json', [ - 'main_block' => json_encode([ - 'error' => [ - 'title' => $e->getMessage() - ] - ]) - ]))->getOutput(); - - break; - - default: - echo (new CView('general.warning', [ - 'header' => $e->getMessage(), - 'messages' => [], - 'theme' => getUserTheme(CWebUser::$data) - ]))->getOutput(); - } + catch (CPageNotFoundException $e) { + http_response_code(404); - session_write_close(); - exit(); + self::terminateWithError($router, $e->getMessage()); + } + catch (Exception $e) { + self::terminateWithError($router, $e->getMessage()); } } @@ -810,6 +793,48 @@ class ZBase { exit(); } + private static function terminateWithError(CRouter $router, string $error): void { + switch ($router->getLayout()) { + case 'layout.json': + case 'layout.widget': + $layout = 'layout.json'; + break; + + default: + if ((array_key_exists('CONTENT_TYPE', $_SERVER) && $_SERVER['CONTENT_TYPE'] === 'application/json') + || (array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) + && strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'], 'XMLHttpRequest') == 0)) { + $layout = 'layout.json'; + } + else { + $layout = 'general.warning'; + } + } + + switch ($layout) { + case 'layout.json': + echo (new CView('layout.json', [ + 'main_block' => json_encode([ + 'error' => [ + 'title' => $error + ] + ]) + ]))->getOutput(); + + break; + + default: + echo (new CView('general.warning', [ + 'header' => $error, + 'messages' => [], + 'theme' => getUserTheme(CWebUser::$data) + ]))->getOutput(); + } + + session_write_close(); + exit(); + } + /** * Set layout mode using URL parameters. */ diff --git a/ui/include/classes/mvc/CPageNotFoundException.php b/ui/include/classes/mvc/CPageNotFoundException.php new file mode 100644 index 00000000000..648ac816f2d --- /dev/null +++ b/ui/include/classes/mvc/CPageNotFoundException.php @@ -0,0 +1,27 @@ +<?php declare(strict_types = 0); +/* +** Zabbix +** Copyright (C) 2001-2022 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +class CPageNotFoundException extends Exception { + + public function __construct($code = 0, Throwable $previous = null) { + parent::__construct(_('Page not found'), $code, $previous); + } +} diff --git a/ui/js/class.dashboard.js b/ui/js/class.dashboard.js index e7ba2b059a6..2be2e1a6e4c 100644 --- a/ui/js/class.dashboard.js +++ b/ui/js/class.dashboard.js @@ -86,7 +86,7 @@ class CDashboard extends CBaseComponent { this._max_rows = max_rows; this._widget_min_rows = widget_min_rows; this._widget_max_rows = widget_max_rows; - this._widget_defaults = {...widget_defaults}; // force object + this._widget_defaults = {...widget_defaults}; this._widget_last_type = widget_last_type; this._is_editable = is_editable; this._is_edit_mode = is_edit_mode; diff --git a/ui/js/common.js b/ui/js/common.js index b17d0317b8c..bad37ea49a6 100644 --- a/ui/js/common.js +++ b/ui/js/common.js @@ -410,6 +410,26 @@ function PopUp(action, parameters, { overlay.recoverFocus(); overlay.containFocus(); + }) + .fail((resp) => { + const error = resp.responseJSON !== undefined && resp.responseJSON.error !== undefined + ? resp.responseJSON.error + : {title: t('Unexpected server error.')}; + + overlay.setProperties({ + content: makeMessageBox('bad', error.messages, error.title, false), + buttons: [ + { + 'title': t('Cancel'), + 'class': 'btn-alt js-cancel', + 'cancel': true, + 'action': function() {} + } + ] + }); + + overlay.recoverFocus(); + overlay.containFocus(); }); addToOverlaysStack(overlay); |