From 340278b59c502c225431a69d25ea8f48e82b0c42 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 30 Apr 2014 01:30:49 +0400 Subject: [PATCH] Fixes #3183: fixed regression after #3175 --- framework/views/errorHandler/error.php | 5 ++-- framework/views/errorHandler/exception.php | 23 ++++++++++++------- .../views/errorHandler/previousException.php | 5 ++-- framework/web/ErrorHandler.php | 13 +++++++++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/framework/views/errorHandler/error.php b/framework/views/errorHandler/error.php index 22b35121df..f3f1e52c5c 100644 --- a/framework/views/errorHandler/error.php +++ b/framework/views/errorHandler/error.php @@ -8,9 +8,8 @@ if ($exception instanceof \yii\web\HttpException) { } else { $code = $exception->getCode(); } -if ($exception instanceof \yii\base\Exception) { - $name = $exception->getName(); -} else { +$name = $handler->getExceptionName($exception); +if ($name === null) { $name = 'Error'; } if ($code) { diff --git a/framework/views/errorHandler/exception.php b/framework/views/errorHandler/exception.php index 1b7629bcd9..0dc0cb95bd 100644 --- a/framework/views/errorHandler/exception.php +++ b/framework/views/errorHandler/exception.php @@ -12,12 +12,16 @@ <?php + $name = $handler->getExceptionName($exception); if ($exception instanceof \yii\web\HttpException) { - echo (int) $exception->statusCode . ' ' . $handler->htmlEncode($exception->getName()); - } elseif ($exception instanceof \yii\base\Exception) { - echo $handler->htmlEncode($exception->getName() . ' – ' . get_class($exception)); + echo (int) $exception->statusCode . ' ' . $handler->htmlEncode($name); } else { - echo $handler->htmlEncode(get_class($exception)); + $name = $handler->getExceptionName($exception); + if ($name !== null) { + echo $handler->htmlEncode($name . ' – ' . get_class($exception)); + } else { + echo $handler->htmlEncode(get_class($exception)); + } } ?> @@ -331,11 +335,14 @@ html,body{ if ($exception instanceof \yii\web\HttpException) { echo '' . $handler->createHttpStatusLink($exception->statusCode, $handler->htmlEncode($exception->getName())) . ''; echo ' – ' . $handler->addTypeLinks(get_class($exception)); - } elseif ($exception instanceof \yii\base\Exception) { - echo '' . $handler->htmlEncode($exception->getName()) . ''; - echo ' – ' . $handler->addTypeLinks(get_class($exception)); } else { - echo '' . $handler->htmlEncode(get_class($exception)) . ''; + $name = $handler->getExceptionName($exception); + if ($name !== null) { + echo '' . $handler->htmlEncode($name) . ''; + echo ' – ' . $handler->addTypeLinks(get_class($exception)); + } else { + echo '' . $handler->htmlEncode(get_class($exception)) . ''; + } } ?> diff --git a/framework/views/errorHandler/previousException.php b/framework/views/errorHandler/previousException.php index 8376434625..762532bd6c 100644 --- a/framework/views/errorHandler/previousException.php +++ b/framework/views/errorHandler/previousException.php @@ -8,8 +8,9 @@

Caused by: - - htmlEncode($exception->getName()) ?> – + getExceptionName($exception); + if ($name !== null): ?> + htmlEncode($name) ?>addTypeLinks(get_class($exception)) ?> htmlEncode(get_class($exception)) ?> diff --git a/framework/web/ErrorHandler.php b/framework/web/ErrorHandler.php index 2c419a3fc0..58ca13ca5d 100644 --- a/framework/web/ErrorHandler.php +++ b/framework/web/ErrorHandler.php @@ -379,4 +379,17 @@ class ErrorHandler extends \yii\base\ErrorHandler return $out; } + + /** + * Returns human-readable exception name + * @param \Exception $exception + * @return string human-readable exception name or null if it cannot be determined + */ + public function getExceptionName($exception) + { + if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) { + return $exception->getName(); + } + return null; + } }