當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。