当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpException类代码示例

本文整理汇总了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]);
     }
 }
开发者ID:rubedkhan2149,项目名称:2149,代码行数:30,代码来源:ErrorAction.php

示例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;
 }
开发者ID:anihy,项目名称:yii2-account,代码行数:16,代码来源:LBErrorHandler.php

示例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);
 }
开发者ID:chatbox-inc,项目名称:lumen-providers,代码行数:15,代码来源:RestAPIRenderer.php

示例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);
 }
开发者ID:jwdeitch,项目名称:components,代码行数:13,代码来源:ClientException.php

示例5: __construct

 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Not Found';
     }
     parent::__construct($message, 404, $previous);
 }
开发者ID:rsky,项目名称:symfony,代码行数:7,代码来源:NotFoundHttpException.php

示例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);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:13,代码来源:NotAcceptableException.php

示例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);
 }
开发者ID:rlugojr,项目名称:cakephp,代码行数:13,代码来源:ServiceUnavailableException.php

示例8: __construct

 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Forbidden';
     }
     parent::__construct($message, 403, $previous);
 }
开发者ID:rsky,项目名称:symfony,代码行数:7,代码来源:ForbiddenHttpException.php

示例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);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:13,代码来源:MethodNotAllowedException.php

示例10: __construct

 public function __construct($message = '', $code = 0, \Exception $previous = null)
 {
     if (!$message) {
         $message = 'Unauthorized';
     }
     parent::__construct($message, 401, $previous);
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:7,代码来源:UnauthorizedHttpException.php

示例11: __construct

 public function __construct($message = '')
 {
     if (!$message) {
         $message = 'Not Found';
     }
     parent::__construct($message, 404);
 }
开发者ID:robo47,项目名称:symfony,代码行数:7,代码来源:NotFoundHttpException.php

示例12: __construct

 public function __construct($message = null, $code = 404)
 {
     if (empty($message)) {
         $message = 'Not Found';
     }
     parent::__construct($message, $code);
 }
开发者ID:exonintrendo,项目名称:Primer,代码行数:7,代码来源:NotFoundException.php

示例13: __construct

 public function __construct($message = '')
 {
     if (!$message) {
         $message = 'Forbidden';
     }
     parent::__construct($message, 403);
 }
开发者ID:CodingFabian,项目名称:symfony,代码行数:7,代码来源:ForbiddenHttpException.php

示例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);
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:13,代码来源:BadRequestException.php

示例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);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:13,代码来源:GoneException.php


注:本文中的HttpException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。