本文整理汇总了PHP中HttpException类的典型用法代码示例。如果您正苦于以下问题:PHP HttpException类的具体用法?PHP HttpException怎么用?PHP HttpException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
// action has been invoked not from error handler, but by direct route, so we display '404 Not Found'
$exception = new HttpException(404, Yii::t('yii', 'Page not found.'));
}
if ($exception instanceof HttpException) {
$code = $exception->statusCode;
} else {
$code = $exception->getCode();
}
if ($exception instanceof Exception) {
$name = $exception->getName();
} else {
$name = $this->defaultName ?: Yii::t('yii', 'Error');
}
if ($code) {
$name .= " (#{$code})";
}
if ($exception instanceof UserException) {
$message = $exception->getMessage();
} else {
$message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
}
if (Yii::$app->getRequest()->getIsAjax()) {
return "{$name}: {$message}";
} else {
return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
}
}
示例2: convertExceptionToArray
/**
* Converts an exception into an array.
* @param \Exception $exception the exception being converted
* @return array the array representation of the exception.
*/
protected function convertExceptionToArray($exception)
{
if (!YII_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) {
$exception = new HttpException(500, 'There was an error at the server.');
}
$array = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
if ($exception instanceof LBUserException) {
$array['data'] = $exception->getErrors();
}
return $array;
}
示例3: renderAsRestAPI
public function renderAsRestAPI($request, \Exception $e)
{
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
} elseif ($e instanceof AuthorizationException) {
$e = new HttpException(403, $e->getMessage());
} elseif ($e instanceof ValidationException && $e->getResponse()) {
return $e->getResponse();
}
$fe = FlattenException::create($e);
$data = env("APP_DEBUG", false) ? $fe->toArray() : ["message" => "whoops, something wrong."];
return JsonResponse::create($data, 500);
}
示例4: __construct
/**
* Code and message positions are reverted.
*
* @param int $code
* @param string $message
*/
public function __construct($code = null, $message = "")
{
if (empty($code) && empty($this->code)) {
$code = self::NOT_FOUND;
}
parent::__construct($message, $code);
}
示例5: __construct
public function __construct($message = '', $code = 0, \Exception $previous = null)
{
if (!$message) {
$message = 'Not Found';
}
parent::__construct($message, 404, $previous);
}
示例6: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Not Acceptable' will be the message
* @param int $code Status code, defaults to 406
*/
public function __construct($message = null, $code = 406)
{
if (empty($message)) {
$message = 'Not Acceptable';
}
parent::__construct($message, $code);
}
示例7: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Service Unavailable' will be the message
* @param int $code Status code, defaults to 503
*/
public function __construct($message = null, $code = 503)
{
if (empty($message)) {
$message = 'Service Unavailable';
}
parent::__construct($message, $code);
}
示例8: __construct
public function __construct($message = '', $code = 0, \Exception $previous = null)
{
if (!$message) {
$message = 'Forbidden';
}
parent::__construct($message, 403, $previous);
}
示例9: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Method Not Allowed' will be the message
* @param int $code Status code, defaults to 405
*/
public function __construct($message = null, $code = 405)
{
if (empty($message)) {
$message = 'Method Not Allowed';
}
parent::__construct($message, $code);
}
示例10: __construct
public function __construct($message = '', $code = 0, \Exception $previous = null)
{
if (!$message) {
$message = 'Unauthorized';
}
parent::__construct($message, 401, $previous);
}
示例11: __construct
public function __construct($message = '')
{
if (!$message) {
$message = 'Not Found';
}
parent::__construct($message, 404);
}
示例12: __construct
public function __construct($message = null, $code = 404)
{
if (empty($message)) {
$message = 'Not Found';
}
parent::__construct($message, $code);
}
示例13: __construct
public function __construct($message = '')
{
if (!$message) {
$message = 'Forbidden';
}
parent::__construct($message, 403);
}
示例14: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Bad Request' will be the message
* @param int $code Status code, defaults to 400
*/
public function __construct($message = null, $code = 400)
{
if (empty($message)) {
$message = 'Bad Request';
}
parent::__construct($message, $code);
}
示例15: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Gone' will be the message
* @param int $code Status code, defaults to 410
*/
public function __construct($message = null, $code = 410)
{
if (empty($message)) {
$message = 'Gone';
}
parent::__construct($message, $code);
}