From d8160624967ca8f221819a16d1e89b159838661c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20=C5=A0imk=C5=ABnas?= Date: Sat, 21 Oct 2023 11:27:28 +0300 Subject: [PATCH] Proper handling of Ajax exceptions --- modules/cms/classes/Controller.php | 6 +++--- modules/cms/lang/en/lang.php | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index dd67cc728c..14b7c9a68b 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -13,7 +13,7 @@ use Session; use Request; use Response; -use Exception; +use Throwable; use SystemException; use BackendAuth; use Twig\Environment as TwigEnvironment; @@ -778,8 +778,8 @@ protected function execAjaxHandlers() $responseContents['X_WINTER_ERROR_MESSAGE'] = $ex->getMessage(); throw new AjaxException($responseContents); } - catch (Exception $ex) { - throw $ex; + catch (Throwable $ex) { + throw new SystemException(Lang::get('cms::lang.ajax_handler.error_occurred'), previous: $ex); } } diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index fa970bfe5c..8cc16e2a56 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -169,6 +169,7 @@ 'ajax_handler' => [ 'invalid_name' => 'Invalid AJAX handler name: :name.', 'not_found' => "AJAX handler ':name' was not found.", + 'error_occurred' => 'An error occurred while executing the AJAX handler.', ], 'cms' => [ 'menu_label' => 'CMS',