Commit 340278b5 by Alexander Makarov

Fixes #3183: fixed regression after #3175

parent 468e4191
...@@ -8,9 +8,8 @@ if ($exception instanceof \yii\web\HttpException) { ...@@ -8,9 +8,8 @@ if ($exception instanceof \yii\web\HttpException) {
} else { } else {
$code = $exception->getCode(); $code = $exception->getCode();
} }
if ($exception instanceof \yii\base\Exception) { $name = $handler->getExceptionName($exception);
$name = $exception->getName(); if ($name === null) {
} else {
$name = 'Error'; $name = 'Error';
} }
if ($code) { if ($code) {
......
...@@ -12,12 +12,16 @@ ...@@ -12,12 +12,16 @@
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title><?php <title><?php
$name = $handler->getExceptionName($exception);
if ($exception instanceof \yii\web\HttpException) { if ($exception instanceof \yii\web\HttpException) {
echo (int) $exception->statusCode . ' ' . $handler->htmlEncode($exception->getName()); echo (int) $exception->statusCode . ' ' . $handler->htmlEncode($name);
} elseif ($exception instanceof \yii\base\Exception) {
echo $handler->htmlEncode($exception->getName() . ' – ' . get_class($exception));
} else { } 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));
}
} }
?></title> ?></title>
...@@ -331,11 +335,14 @@ html,body{ ...@@ -331,11 +335,14 @@ html,body{
if ($exception instanceof \yii\web\HttpException) { if ($exception instanceof \yii\web\HttpException) {
echo '<span>' . $handler->createHttpStatusLink($exception->statusCode, $handler->htmlEncode($exception->getName())) . '</span>'; echo '<span>' . $handler->createHttpStatusLink($exception->statusCode, $handler->htmlEncode($exception->getName())) . '</span>';
echo ' &ndash; ' . $handler->addTypeLinks(get_class($exception)); echo ' &ndash; ' . $handler->addTypeLinks(get_class($exception));
} elseif ($exception instanceof \yii\base\Exception) {
echo '<span>' . $handler->htmlEncode($exception->getName()) . '</span>';
echo ' &ndash; ' . $handler->addTypeLinks(get_class($exception));
} else { } else {
echo '<span>' . $handler->htmlEncode(get_class($exception)) . '</span>'; $name = $handler->getExceptionName($exception);
if ($name !== null) {
echo '<span>' . $handler->htmlEncode($name) . '</span>';
echo ' &ndash; ' . $handler->addTypeLinks(get_class($exception));
} else {
echo '<span>' . $handler->htmlEncode(get_class($exception)) . '</span>';
}
} }
?></h1> ?></h1>
<?php endif; ?> <?php endif; ?>
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
<span class="arrow">&crarr;</span> <span class="arrow">&crarr;</span>
<h2> <h2>
<span>Caused by:</span> <span>Caused by:</span>
<?php if ($exception instanceof \yii\base\Exception): ?> <?php $name = $handler->getExceptionName($exception);
<span><?= $handler->htmlEncode($exception->getName()) ?></span> &ndash; if ($name !== null): ?>
<span><?= $handler->htmlEncode($name) ?></span> &ndash;
<?= $handler->addTypeLinks(get_class($exception)) ?> <?= $handler->addTypeLinks(get_class($exception)) ?>
<?php else: ?> <?php else: ?>
<span><?= $handler->htmlEncode(get_class($exception)) ?></span> <span><?= $handler->htmlEncode(get_class($exception)) ?></span>
......
...@@ -379,4 +379,17 @@ class ErrorHandler extends \yii\base\ErrorHandler ...@@ -379,4 +379,17 @@ class ErrorHandler extends \yii\base\ErrorHandler
return $out; 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;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment