本文整理汇总了PHP中Exception::getHttpCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::getHttpCode方法的具体用法?PHP Exception::getHttpCode怎么用?PHP Exception::getHttpCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception::getHttpCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleException
/**
* Exeptions are returned to client in the form
* of a message in the 'error' element
* Appropriate http response code is used
*
* @param \Exception $e
*/
protected function handleException(\Exception $e)
{
if (!$this->restful) {
throw $e;
}
if ($e instanceof \Lampcms\HttpResponseCodeException) {
$code = $e->getHttpCode();
$this->Registry->Response->setHttpCode($code);
/**
* @todo if $code = 405 and bRequirePost then
* set extra header Allow: POST
* This is to comply with RFC
*/
} else {
$this->Registry->Response->setHttpCode(500);
}
$err = \strip_tags($e->getMessage());
$err2 = 'API Exception caught in: ' . $e->getFile() . ' on line: ' . $e->getLine() . ' error: ' . $err;
d($err2);
$this->Output->setData(array('error' => $err));
$this->Registry->Response->setBody($this->Output);
}
示例2: handleException
/**
* {@inheritDoc}
*/
public function handleException(\Exception $e)
{
$refl = new \ReflectionClass($e);
if ($e instanceof HttpExceptionInterface) {
$title = sprintf('%s::%s', $refl->getShortName(), $e->getErrorType());
$detail = $e->getMessage();
$status = $e->getHttpCode();
} else {
$title = $refl->getShortName();
$detail = 'Oh no! Something bad happened on the server! Please try again.';
$status = 500;
}
$serialized = $this->getSerializer()->serializeError($title, $detail, $status);
$payload = new Rest\RestPayload($serialized);
return $this->createRestResponse($status, $payload);
}
示例3: handleException
/**
* handles an exception when loading a page
*
* @param Exception $e
* @param string $controller name of controller
* @param string $action name of action
* @return void
*/
public function handleException(\Exception $e, $controller = null, $action = null)
{
if ($this->_delegate) {
$this->_delegate->appCaughtException($e, $controller, $action);
}
// turn other exceptions into sonic exceptions
if (!$e instanceof Exception) {
$e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
}
// only set the http code if output hasn't started
if (!headers_sent()) {
header($e->getHttpCode());
}
$json = false;
$id = null;
// in turbo mode we have to write the exception markup out to the
// same div created before the exception was triggered. this means
// we have to get the id based on the controller and action that the
// exception came from
if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
$json = true;
$id = View::generateId($controller, $action);
}
$completed = false;
// controller and action are only null if this is a page not found
// because we were not able to match any routes. in all other cases
// we can get the initial controller and action to determine if it has
// completed
if ($controller !== null && $action !== null) {
$req = $this->getRequest();
$first_controller = $req->getControllerName();
$first_action = $req->getAction();
$completed = $this->getController($first_controller)->hasCompleted($first_action);
}
$args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
return $this->_runController('main', 'error', $args, $json, $id);
}
示例4: handleException
public function handleException(\Exception $e, $controller = null, $action = null)
{
if ($this->_delegate) {
$this->_delegate->appCaughtException($e, $controller, $action);
}
if (!$e instanceof Exception) {
$e = new Exception($e->getMessage(), Exception::INTERNAL_SERVER_ERROR, $e);
}
if (!headers_sent()) {
header($e->getHttpCode());
}
$json = false;
$id = null;
if ($this->getSetting(self::TURBO) && $this->_layout_processed) {
$json = true;
$id = View::generateId($controller, $action);
}
$completed = false;
if ($controller !== null && $action !== null) {
$req = $this->getRequest();
$first_controller = $req->getControllerName();
$first_action = $req->getAction();
$completed = $this->getController($first_controller)->hasCompleted($first_action);
}
$args = array('exception' => $e, 'top_level_exception' => !$completed, 'from_controller' => $controller, 'from_action' => $action);
return $this->_runController('main', 'error', $args, $json, $id);
}