Commit 398ac254 by Qiang Xue

added UserException.

parent af4455eb
...@@ -464,7 +464,7 @@ class Application extends Module ...@@ -464,7 +464,7 @@ class Application extends Module
*/ */
public function renderException($exception) public function renderException($exception)
{ {
if ($exception instanceof Exception && ($exception->causedByUser || !YII_DEBUG)) { if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
$message = $exception->getName() . ': ' . $exception->getMessage(); $message = $exception->getName() . ': ' . $exception->getMessage();
} else { } else {
$message = YII_DEBUG ? (string)$exception : 'Error: ' . $exception->getMessage(); $message = YII_DEBUG ? (string)$exception : 'Error: ' . $exception->getMessage();
......
...@@ -81,7 +81,7 @@ class ErrorHandler extends Component ...@@ -81,7 +81,7 @@ class ErrorHandler extends Component
\Yii::$application->renderException($exception); \Yii::$application->renderException($exception);
} else { } else {
$view = new View($this); $view = new View($this);
if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) { if (!YII_DEBUG || $exception instanceof UserException) {
$viewName = $this->errorView; $viewName = $this->errorView;
} else { } else {
$viewName = $this->exceptionView; $viewName = $this->exceptionView;
...@@ -256,7 +256,7 @@ class ErrorHandler extends Component ...@@ -256,7 +256,7 @@ class ErrorHandler extends Component
public function renderAsHtml($exception) public function renderAsHtml($exception)
{ {
$view = new View($this); $view = new View($this);
if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) { if (!YII_DEBUG || $exception instanceof UserException) {
$viewName = $this->errorView; $viewName = $this->errorView;
} else { } else {
$viewName = $this->exceptionView; $viewName = $this->exceptionView;
......
...@@ -18,11 +18,6 @@ namespace yii\base; ...@@ -18,11 +18,6 @@ namespace yii\base;
class Exception extends \Exception class Exception extends \Exception
{ {
/** /**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = false;
/**
* @return string the user-friendly name of this exception * @return string the user-friendly name of this exception
*/ */
public function getName() public function getName()
......
...@@ -19,16 +19,12 @@ namespace yii\base; ...@@ -19,16 +19,12 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class HttpException extends Exception class HttpException extends UserException
{ {
/** /**
* @var integer HTTP status code, such as 403, 404, 500, etc. * @var integer HTTP status code, such as 403, 404, 500, etc.
*/ */
public $statusCode; public $statusCode;
/**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = true;
/** /**
* Constructor. * Constructor.
......
...@@ -15,14 +15,9 @@ namespace yii\base; ...@@ -15,14 +15,9 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class InvalidRequestException extends \Exception class InvalidRequestException extends UserException
{ {
/** /**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = true;
/**
* @return string the user-friendly name of this exception * @return string the user-friendly name of this exception
*/ */
public function getName() public function getName()
......
...@@ -15,14 +15,9 @@ namespace yii\base; ...@@ -15,14 +15,9 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class InvalidRouteException extends \Exception class InvalidRouteException extends UserException
{ {
/** /**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = true;
/**
* @return string the user-friendly name of this exception * @return string the user-friendly name of this exception
*/ */
public function getName() public function getName()
......
<?php
/**
* UserException class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* UserException is the base class for exceptions that are meant to be shown to end users.
* Such exceptions are often caused by mistakes of end users.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class UserException extends Exception
{
}
...@@ -126,8 +126,7 @@ class Application extends \yii\base\Application ...@@ -126,8 +126,7 @@ class Application extends \yii\base\Application
'message' => 'yii\console\controllers\MessageController', 'message' => 'yii\console\controllers\MessageController',
'help' => 'yii\console\controllers\HelpController', 'help' => 'yii\console\controllers\HelpController',
'migrate' => 'yii\console\controllers\MigrateController', 'migrate' => 'yii\console\controllers\MigrateController',
'shell' => 'yii\console\controllers\ShellController', 'app' => 'yii\console\controllers\CreateController',
'create' => 'yii\console\controllers\CreateController',
); );
} }
......
...@@ -15,14 +15,9 @@ namespace yii\console; ...@@ -15,14 +15,9 @@ namespace yii\console;
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Exception extends \yii\base\Exception class Exception extends \yii\base\UserException
{ {
/** /**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = true;
/**
* @return string the user-friendly name of this exception * @return string the user-friendly name of this exception
*/ */
public function getName() public function getName()
......
...@@ -52,7 +52,7 @@ class HelpController extends Controller ...@@ -52,7 +52,7 @@ class HelpController extends Controller
* @return integer the exit status * @return integer the exit status
* @throws Exception if the command for help is unknown * @throws Exception if the command for help is unknown
*/ */
public function actionIndex($command) public function actionIndex($command = null)
{ {
if ($command !== null) { if ($command !== null) {
$result = Yii::$application->createController($command); $result = Yii::$application->createController($command);
...@@ -147,10 +147,10 @@ class HelpController extends Controller ...@@ -147,10 +147,10 @@ class HelpController extends Controller
if ($commands !== array()) { if ($commands !== array()) {
echo "The following commands are available:\n\n"; echo "The following commands are available:\n\n";
foreach ($commands as $command) { foreach ($commands as $command) {
echo " * $command\n"; echo "* $command\n";
} }
echo "\nTo see the help of each command, enter:\n"; echo "\nTo see the help of each command, enter:\n";
echo "\n yiic help <command-name>\n\n"; echo "\n yiic help <command-name>\n\n";
} else { } else {
echo "\nNo commands are found.\n"; echo "\nNo commands are found.\n";
} }
......
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