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


PHP Exception::getHttpStatus方法代码示例

本文整理汇总了PHP中Exception::getHttpStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getHttpStatus方法的具体用法?PHP Exception::getHttpStatus怎么用?PHP Exception::getHttpStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::getHttpStatus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 public static function process(\Exception $e, Request $request, Response $response)
 {
     if ($e instanceof BaseException) {
         $response->withStatus($e->getHttpStatus());
         $response->write(Code::json($e->getCode(), $e->getMessage()));
     } else {
         if ($e instanceof MethodNotAllowedException) {
             $response->withStatus(405);
             $allow = implode(', ', $e->getAllowedMethods());
             $response->withHeader('Allow', $allow);
             $response->write(Code::json(Code::METHOD_NOT_ALLOWED, 'allow: ' . $allow));
         } else {
             if ($e instanceof NotFoundException) {
                 $response->withStatus(404);
                 $response->write(Code::json(Code::RESOURCE_NOT_FOUND));
             } else {
                 if ($e instanceof UnsupportedMediaType) {
                     $response->withStatus(415);
                     $response->write(Code::json(Code::UNSUPPORTED_MEDIA_TYPE, $e->getMessage()));
                 } else {
                     if ($e instanceof BadBodyException) {
                         $response->withStatus(400);
                         $response->write(Code::json(Code::BAD_BODY, $e->getMessage()));
                     } else {
                         if ($e instanceof \PDOException) {
                             $response->withStatus(502);
                             $response->write(Code::json(Code::DATABASE_ERROR));
                             trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                         } else {
                             if ($e instanceof \RedisException) {
                                 $response->withStatus(502);
                                 $response->write(Code::json(Code::CACHE_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             } else {
                                 $response->withStatus(500);
                                 $response->write(Code::json(Code::INTERNAL_SERVER_ERROR));
                                 trigger_error(Str::exceptionToString($e), E_USER_WARNING);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:raframework,项目名称:ra,代码行数:45,代码来源:ExceptionHandler.php

示例2: displayError

 public function displayError(\Exception $exception)
 {
     $originalException = $exception;
     $code = $exception->getCode();
     //if extended exception was thrown, we have additional details
     if ($exception instanceof ExceptionInterface) {
         $httpStatus = $exception->getHttpStatus();
         $details = $exception->getDetails();
     } else {
         $httpStatus = 500;
         $details = array();
     }
     $development = ini_get('display_errors') && APPLICATION_ENV === "development";
     $message = $exception->getMessage();
     //determine whether this is an error the user should see
     if (($code < 100000 || $code >= 200000) && !$development) {
         //exception code is in the range where the message should be
         //displayed to the user
         $message = "An unexpected error has occurred";
         $details['detail'] = "This might be the developer's fault. The developer has been notified of this occurrence";
     }
     //show exception details if in development //redundant conditional?
     if ($development) {
         $exceptions = array();
         do {
             $exceptions['exception'][] = array('message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString());
         } while ($exception = $exception->getPrevious());
         $details['exceptions'] = $exceptions;
     }
     //TODO attach to this event, email if not in user visible range
     $this->getEventManager()->trigger('displayError', $this, $originalException);
     $result = $this->getError($message, $details, $httpStatus, $code);
     return $this->display($result);
 }
开发者ID:shinymayhem,项目名称:shiny-rest,代码行数:34,代码来源:AbstractRestfulController.php

示例3: output

 /**
  * 输出异常信息
  * @param  \Exception $exception 
  * @param  Array      $vars      异常信息
  * @return null
  */
 public static function output(\Exception $exception, array $vars)
 {
     if ($exception instanceof Exception) {
         http_response_code($exception->getHttpStatus());
     } else {
         http_response_code(500);
     }
     // header('Content-Type: application/json');
     // echo json_encode($vars);exit;
     $type = Config::get('default_return_type');
     if (IS_API && 'html' != $type) {
         // 异常信息输出监听
         APP_HOOK && Hook::listen('error_output', $data);
         // 输出异常内容
         Response::send($data, $type, Config::get('response_return'));
     } else {
         ob_end_clean();
         extract($vars);
         include Config::get('exception_tmpl');
     }
 }
开发者ID:gg1122,项目名称:think,代码行数:27,代码来源:Error.php

示例4: getSeverityFromException

 /**
  * Given an exception, return a severity level for logging purposes.
  *
  * @param \Exception $error Exception to analyze
  *
  * @return int
  */
 protected function getSeverityFromException($error)
 {
     // Treat unexpected or 5xx errors as more severe than 4xx errors.
     if ($error instanceof \VuFind\Exception\HttpStatusInterface && in_array($error->getHttpStatus(), [403, 404])) {
         return BaseLogger::WARN;
     }
     return BaseLogger::CRIT;
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:15,代码来源:Logger.php

示例5: convertException

 /**
  * Interpret the given exception and decide whether it is due to an
  * unavailable storage, invalid storage or other.
  * This will either throw StorageInvalidException, StorageNotAvailableException
  * or do nothing.
  *
  * @param Exception $e sabre exception
  *
  * @throws StorageInvalidException if the storage is invalid, for example
  * when the authentication expired or is invalid
  * @throws StorageNotAvailableException if the storage is not available,
  * which might be temporary
  */
 private function convertException(Exception $e)
 {
     \OCP\Util::writeLog('files_external', $e->getMessage(), \OCP\Util::ERROR);
     if ($e instanceof ClientHttpException) {
         if ($e->getHttpStatus() === 401) {
             // either password was changed or was invalid all along
             throw new StorageInvalidException(get_class($e) . ': ' . $e->getMessage());
         } else {
             if ($e->getHttpStatus() === 405) {
                 // ignore exception for MethodNotAllowed, false will be returned
                 return;
             }
         }
         throw new StorageNotAvailableException(get_class($e) . ': ' . $e->getMessage());
     } else {
         if ($e instanceof ClientException) {
             // connection timeout or refused, server could be temporarily down
             throw new StorageNotAvailableException(get_class($e) . ': ' . $e->getMessage());
         } else {
             if ($e instanceof \InvalidArgumentException) {
                 // parse error because the server returned HTML instead of XML,
                 // possibly temporarily down
                 throw new StorageNotAvailableException(get_class($e) . ': ' . $e->getMessage());
             } else {
                 if ($e instanceof StorageNotAvailableException || $e instanceof StorageInvalidException) {
                     // rethrow
                     throw $e;
                 }
             }
         }
     }
     // TODO: only log for now, but in the future need to wrap/rethrow exception
 }
开发者ID:adolfo2103,项目名称:hcloudfilem,代码行数:46,代码来源:dav.php

示例6: output

 /**
  * 输出异常信息
  *
  * @param  \Exception $exception
  * @param  array $data 异常信息
  *
  * @return void
  */
 public static function output($exception, array $data)
 {
     self::httpResponseCode($exception instanceof Exception ? $exception->getHttpStatus() : 500);
     $type = Config::get('default_return_type');
     if (!APP_DEBUG && !Config::get('show_error_msg')) {
         // 不显示详细错误信息
         $data['message'] = Config::get('error_message');
         ##}
         ##if (IS_API && 'html' != $type) {
         // 异常信息输出监听
         ##APP_HOOK && Hook::listen('error_output', $data);
         // 输出异常内容
         ##Response::send($data, $type, Config::get('response_return'));
     } else {
         //ob_end_clean();
         extract($data);
         //             var_dump(Config::get('exception_tmpl'));exit;
         include Config::get('exception_tmpl');
     }
 }
开发者ID:supefun,项目名称:SupeFramework,代码行数:28,代码来源:Error.php


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