mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-20 16:38:22 +08:00
Added support for previous exceptions
PHP supports exception stacks since 5.3 so we should use it. Also Errorhandler is now able to display the stack: #297
This commit is contained in:
@@ -48,6 +48,10 @@ class ErrorHandler extends Component
|
||||
* @var string the path of the view file for rendering exceptions and errors call stack element.
|
||||
*/
|
||||
public $callStackItemView = '@yii/views/errorHandler/callStackItem.php';
|
||||
/**
|
||||
* @var string the path of the view file for rendering previous exceptions.
|
||||
*/
|
||||
public $previousExceptionView = '@yii/views/errorHandler/previousException.php';
|
||||
/**
|
||||
* @var \Exception the exception that is being handled currently.
|
||||
*/
|
||||
@@ -160,6 +164,24 @@ class ErrorHandler extends Component
|
||||
return '<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#' . (int)$statusCode .'" target="_blank">HTTP ' . (int)$statusCode . ' – ' . $statusDescription . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the previous exception stack for a given Exception.
|
||||
* @param \Exception $exception the exception whose precursors should be rendered.
|
||||
* @return string HTML content of the rendered previous exceptions.
|
||||
* Empty string if there are none.
|
||||
*/
|
||||
public function renderPreviousExceptions($exception)
|
||||
{
|
||||
if (($previous = $exception->getPrevious()) === null) {
|
||||
return '';
|
||||
}
|
||||
$view = new View();
|
||||
return $view->renderFile($this->previousExceptionView, array(
|
||||
'exception' => $previous,
|
||||
'previousHtml' => $this->renderPreviousExceptions($previous),
|
||||
), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a single call stack element.
|
||||
* @param string $file name where call has happened.
|
||||
|
||||
@@ -103,7 +103,7 @@ class HttpException extends UserException
|
||||
if (isset($httpCodes[$this->statusCode])) {
|
||||
return $httpCodes[$this->statusCode];
|
||||
} else {
|
||||
return \Yii::t('yii', 'Error');
|
||||
return 'Error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user