本文整理汇总了PHP中HttpException类的典型用法代码示例。如果您正苦于以下问题:PHP HttpException类的具体用法?PHP HttpException怎么用?PHP HttpException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: exception
function exception(Exception $e)
{
if (ob_get_length() != false) {
@ob_end_clean();
}
$et = typeOf($e);
if ($et == 'FileNotFoundException' || $et == 'NavigationException') {
response::setStatus(404);
header('HTTP/1.1 404 Not Found', true);
printf("<h1>404: Not Found</h1>");
return;
}
if ($et == 'HttpException') {
response::setStatus($e->getCode());
$code = $e->getMessage();
list($code) = explode(':', $code);
$code = str_replace('Error ', '', $code);
$msg = HttpException::getHttpMessage($code);
header('HTTP/1.1 ' . $code . ' ' . $msg . ' ' . $msg);
printf("<h1>%s: %s</h1>\n<pre>%s</pre>", $code, $msg, $msg);
return;
}
response::setStatus(500);
logger::emerg("Unhandled exception: (%s) %s in %s:%d", get_class($e), $e->getMessage(), str_replace(BASE_PATH, '', $e->getFile()), $e->getLine());
header('HTTP/1.1 501 Server Error', true);
$id = uniqid();
$dbg = sprintf("Unhandled exception: (%s) %s\n in %s:%d", get_class($e), $e->getMessage(), str_replace(SYS_PATH, '', $e->getFile()), $e->getLine()) . Console::backtrace(0, $e->getTrace(), true) . "\n" . "Loaded modules:\n" . ModuleManager::debug() . "\n" . request::getDebugInformation();
logger::emerg($dbg);
if (config::get('lepton.mvc.exception.log', false) == true) {
$logfile = config::get('lepton.mvc.exception.logfile', "/tmp/" . $_SERVER['HTTP_HOST'] . "-debug.log");
$log = "=== Unhandled Exception ===\n\n" . $dbg . "\n";
$lf = @fopen($logfile, "a+");
if ($lf) {
fputs($lf, $log);
fclose($lf);
}
}
$ico_error = resource::get('warning.png');
header('content-type: text/html; charset=utf-8');
echo '<html><head><title>Unhandled Exception</title>' . self::$css . self::$js . '</head><body>' . '<div id="box"><div id="left"><img src="' . $ico_error . '" width="32" height="32"></div><div id="main">' . '<h1>An Unhandled Exception Occured</h1>' . '<hr noshade>' . '<p>This means that something didn\'t go quite go as planned. This could be ' . 'caused by one of several reasons, so please be patient and try ' . 'again in a little while.</p>';
if (config::get('lepton.mvc.exception.feedback', false) == true) {
echo '<p>The administrator of the website has been notified about this error. You ' . 'can help us find and fix the problem by writing a line or two about what you were doing when this ' . 'error occured.</p>';
echo '<p id="feedbacklink"><a href="javascript:doFeedback();">If you would like to assist us with more information, please click here</a>.</p>';
echo '<div id="feedback" style="display:none;"><p>Describe in a few short lines what you were doing right before you encountered this error:</p><form action="/errorevent.feedback/' . $id . '" method="post"><div><textarea name="text" style="width:100%; height:50px;"></textarea></div><div style="padding-top:5px; text-align:right;"><input type="button" value=" Close " onclick="closeFeedback();"> <input type="submit" value=" Submit Feedback "></div></form></div>';
}
if (config::get('lepton.mvc.exception.showdebug', false) == true) {
echo '<hr noshade>' . '<a href="javascript:toggleAdvanced();">Details »</a>' . '<pre id="advanced" style="display:none; height:300px;">' . $dbg . '</pre>';
}
echo '<div>' . '</body></html>';
}
开发者ID:noccy80,项目名称:lepton-ng,代码行数:50,代码来源:exception.php
示例5: __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
示例6: __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
示例7: __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
示例8: __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
示例9: __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
示例10: __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
示例11: __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
示例12: __construct
public function __construct($message = '')
{
if (!$message) {
$message = 'Not Found';
}
parent::__construct($message, 404);
}
开发者ID:robo47,项目名称:symfony,代码行数:7,代码来源:NotFoundHttpException.php
示例13: __construct
public function __construct($message = null, $code = 404)
{
if (empty($message)) {
$message = 'Not Found';
}
parent::__construct($message, $code);
}
开发者ID:exonintrendo,项目名称:Primer,代码行数:7,代码来源:NotFoundException.php
示例14: __construct
public function __construct($message = '')
{
if (!$message) {
$message = 'Forbidden';
}
parent::__construct($message, 403);
}
开发者ID:CodingFabian,项目名称:symfony,代码行数:7,代码来源:ForbiddenHttpException.php
示例15: __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
示例16: __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
示例17: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Unavailable For Legal Reasons' will be the message
* @param int $code Status code, defaults to 451
*/
public function __construct($message = null, $code = 451)
{
if (empty($message)) {
$message = 'Unavailable For Legal Reasons';
}
parent::__construct($message, $code);
}
开发者ID:nrother,项目名称:cakephp,代码行数:13,代码来源:UnavailableForLegalReasonsException.php
示例18: __construct
/**
* Constructor
*
* @param string|null $message If no message is given 'Conflict' will be the message
* @param int $code Status code, defaults to 409
*/
public function __construct($message = null, $code = 409)
{
if (empty($message)) {
$message = 'Conflict';
}
parent::__construct($message, $code);
}
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:13,代码来源:ConflictException.php
示例19: __construct
/**
* @param string $location
* @param integer $statusCode
* @param string $message
* @param \Exception|null $previous
*/
public function __construct($location, $statusCode = 302, $message = '', \Exception $previous = null)
{
if ($statusCode < 300 || $statusCode >= 400) {
throw new \InvalidArgumentException('Invalid HTTP redirect status code: ' . $statusCode);
}
parent::__construct($statusCode, ['Location' => $location], $message, $previous);
}
开发者ID:xxoxx,项目名称:php-waf,代码行数:13,代码来源:HttpRedirectException.php
示例20: __construct
/**
* Class constructor.
*
* @param string $location The redirect URL.
* @param int $statusCode The HTTP status code, 3XX.
* @param string $message An optional exception message for debugging.
* @param \Throwable|null $previous An optional previous exception for chaining.
*
* @throws \RuntimeException
*/
public function __construct($location, $statusCode = 302, $message = '', \Throwable $previous = null)
{
if ($statusCode < 300 || $statusCode >= 400) {
throw new \RuntimeException('Invalid HTTP redirect status code: ' . $statusCode);
}
parent::__construct($statusCode, ['Location' => $location]);
}
开发者ID:brick,项目名称:http,代码行数:17,代码来源:HttpRedirectException.php
注:本文中的HttpException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论