Browse Source

added UserException.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
398ac25456
  1. 2
      framework/base/Application.php
  2. 4
      framework/base/ErrorHandler.php
  3. 5
      framework/base/Exception.php
  4. 6
      framework/base/HttpException.php
  5. 7
      framework/base/InvalidRequestException.php
  6. 7
      framework/base/InvalidRouteException.php
  7. 21
      framework/base/UserException.php
  8. 3
      framework/console/Application.php
  9. 7
      framework/console/Exception.php
  10. 2
      framework/console/controllers/HelpController.php

2
framework/base/Application.php

@ -464,7 +464,7 @@ class Application extends Module
*/
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();
} else {
$message = YII_DEBUG ? (string)$exception : 'Error: ' . $exception->getMessage();

4
framework/base/ErrorHandler.php

@ -81,7 +81,7 @@ class ErrorHandler extends Component
\Yii::$application->renderException($exception);
} else {
$view = new View($this);
if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) {
if (!YII_DEBUG || $exception instanceof UserException) {
$viewName = $this->errorView;
} else {
$viewName = $this->exceptionView;
@ -256,7 +256,7 @@ class ErrorHandler extends Component
public function renderAsHtml($exception)
{
$view = new View($this);
if (!YII_DEBUG || $exception instanceof Exception && $exception->causedByUser) {
if (!YII_DEBUG || $exception instanceof UserException) {
$viewName = $this->errorView;
} else {
$viewName = $this->exceptionView;

5
framework/base/Exception.php

@ -18,11 +18,6 @@ namespace yii\base;
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
*/
public function getName()

6
framework/base/HttpException.php

@ -19,16 +19,12 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class HttpException extends Exception
class HttpException extends UserException
{
/**
* @var integer HTTP status code, such as 403, 404, 500, etc.
*/
public $statusCode;
/**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
*/
public $causedByUser = true;
/**
* Constructor.

7
framework/base/InvalidRequestException.php

@ -15,14 +15,9 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com>
* @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
*/
public function getName()

7
framework/base/InvalidRouteException.php

@ -15,14 +15,9 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com>
* @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
*/
public function getName()

21
framework/base/UserException.php

@ -0,0 +1,21 @@
<?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
{
}

3
framework/console/Application.php

@ -126,8 +126,7 @@ class Application extends \yii\base\Application
'message' => 'yii\console\controllers\MessageController',
'help' => 'yii\console\controllers\HelpController',
'migrate' => 'yii\console\controllers\MigrateController',
'shell' => 'yii\console\controllers\ShellController',
'create' => 'yii\console\controllers\CreateController',
'app' => 'yii\console\controllers\CreateController',
);
}

7
framework/console/Exception.php

@ -15,14 +15,9 @@ namespace yii\console;
* @author Qiang Xue <qiang.xue@gmail.com>
* @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
*/
public function getName()

2
framework/console/controllers/HelpController.php

@ -52,7 +52,7 @@ class HelpController extends Controller
* @return integer the exit status
* @throws Exception if the command for help is unknown
*/
public function actionIndex($command)
public function actionIndex($command = null)
{
if ($command !== null) {
$result = Yii::$application->createController($command);

Loading…
Cancel
Save