HttpException.php 1.37 KB
Newer Older
Qiang Xue committed
1 2 3
<?php
/**
 * @link http://www.yiiframework.com/
Qiang Xue committed
4
 * @copyright Copyright (c) 2008 Yii Software LLC
Qiang Xue committed
5 6 7 8 9
 * @license http://www.yiiframework.com/license/
 */

namespace yii\base;

Qiang Xue committed
10

Qiang Xue committed
11 12 13 14 15 16 17 18 19 20
/**
 * HttpException represents an exception caused by an improper request of the end-user.
 *
 * HttpException can be differentiated via its [[statusCode]] property value which
 * keeps a standard HTTP status code (e.g. 404, 500). Error handlers may use this status code
 * to decide how to format the error page.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
Qiang Xue committed
21
class HttpException extends UserException
Qiang Xue committed
22 23 24 25 26 27 28 29 30 31 32
{
	/**
	 * @var integer HTTP status code, such as 403, 404, 500, etc.
	 */
	public $statusCode;

	/**
	 * Constructor.
	 * @param integer $status HTTP status code, such as 404, 500, etc.
	 * @param string $message error message
	 * @param integer $code error code
33
	 * @param \Exception $previous The previous exception used for the exception chaining.
Qiang Xue committed
34
	 */
35
	public function __construct($status, $message = null, $code = 0, \Exception $previous = null)
Qiang Xue committed
36 37
	{
		$this->statusCode = $status;
38
		parent::__construct($message, $code, $previous);
Qiang Xue committed
39
	}
40 41 42 43 44 45

	/**
	 * @return string the user-friendly name of this exception
	 */
	public function getName()
	{
Qiang Xue committed
46 47
		if (isset(\yii\web\Response::$statusTexts[$this->statusCode])) {
			return \yii\web\Response::$statusTexts[$this->statusCode];
resurtm committed
48
		} else {
49
			return 'Error';
resurtm committed
50
		}
51
	}
Qiang Xue committed
52
}