From a0399996aa50dc366ff582b2e343a229f65e8308 Mon Sep 17 00:00:00 2001 From: zhandos Date: Mon, 10 Nov 2025 16:20:06 +0500 Subject: [PATCH 1/2] Added method "fallbackExceptionMessage" to customize fallback exception message --- framework/base/ErrorHandler.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/framework/base/ErrorHandler.php b/framework/base/ErrorHandler.php index 69d91693f54..bfe4b9f2e2b 100644 --- a/framework/base/ErrorHandler.php +++ b/framework/base/ErrorHandler.php @@ -188,7 +188,7 @@ protected function handleFallbackExceptionMessage($exception, $previousException } $msg .= "\n\$_SERVER = " . VarDumper::export($_SERVER); } else { - echo 'An internal server error occurred.'; + echo $this->fallbackExceptionMessage($exception); } error_log($msg); if (defined('HHVM_VERSION')) { @@ -197,6 +197,11 @@ protected function handleFallbackExceptionMessage($exception, $previousException exit(1); } + protected function fallbackExceptionMessage($exception) + { + return 'An internal server error occurred.'; + } + /** * Handles HHVM execution errors such as warnings and notices. * From 3e3c1fbd20b2f678ba7b449c0c7d67c738417658 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 10 Oct 2026 10:23:55 -0300 Subject: [PATCH 2/2] Add `yii\base\ErrorHandler::fallbackExceptionMessage()` to customize the fallback exception message. --- framework/CHANGELOG.md | 1 + framework/base/ErrorHandler.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 2c5fed5b752..09d363a284b 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -42,6 +42,7 @@ Yii Framework 2 Change Log - Bug #21094: Log a warning instead of silently ignoring `$isolationLevel` when `yii\db\Transaction::begin()` is called for a nested transaction (terabytesoftw) - Bug #21086: Allow integer and string keys in the `yii\base\Model::rules()` return annotation (terabytesoftw) - Bug #21115: Fix PHPStan 2.3.0 `parameterByRef.type` error in `yii\db\QueryBuilder::getTableUniqueColumnNames()` (theluckystrike) +- Enh #20681: Add `yii\base\ErrorHandler::fallbackExceptionMessage()` to customize the message shown by `handleFallbackExceptionMessage()` when `YII_DEBUG` is disabled (ZhandosKz, terabytesoftw) 2.0.55 May 09, 2026 ------------------- diff --git a/framework/base/ErrorHandler.php b/framework/base/ErrorHandler.php index aa99f89aa31..9d8588b08eb 100644 --- a/framework/base/ErrorHandler.php +++ b/framework/base/ErrorHandler.php @@ -188,7 +188,7 @@ protected function handleFallbackExceptionMessage($exception, $previousException } $msg .= "\n\$_SERVER = " . VarDumper::export($_SERVER); } else { - echo $this->fallbackExceptionMessage($exception); + echo $this->fallbackExceptionMessage($exception, $previousException); } error_log($msg); if (defined('HHVM_VERSION')) { @@ -197,7 +197,18 @@ protected function handleFallbackExceptionMessage($exception, $previousException exit(1); } - protected function fallbackExceptionMessage($exception) + /** + * Returns the message displayed when an exception is thrown while handling another exception + * and `YII_DEBUG` is disabled. + * + * @param \Throwable $exception Exception that was thrown during main exception processing. + * @param \Throwable $previousException Main exception processed in [[handleException()]]. + * + * @return string the message to be displayed. + * + * @since 2.0.56 + */ + protected function fallbackExceptionMessage($exception, $previousException) { return 'An internal server error occurred.'; }