You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.8 KiB
84 lines
1.8 KiB
<?php
|
|
/**
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
|
* @link http://netmonsters.ru
|
|
* @package Majestic
|
|
* @subpackage app
|
|
* @since 2010-02-25
|
|
*/
|
|
|
|
class ErrorAction extends Action
|
|
{
|
|
|
|
/**
|
|
* @var ErrorException|ErrorHTTPException
|
|
*/
|
|
public $exception;
|
|
|
|
protected $ajax_error = false;
|
|
|
|
public function __construct($exception)
|
|
{
|
|
$this->exception = $exception;
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute()
|
|
{
|
|
if ($this->exception instanceof Error404Exception) {
|
|
$this->template = 404;
|
|
} elseif ($this->exception instanceof ErrorHTTPException) {
|
|
$this->template = 'HTTP';
|
|
} else {
|
|
$this->template = 500;
|
|
}
|
|
$this->logError();
|
|
$this->sendHTTPCode();
|
|
}
|
|
|
|
public function fetch()
|
|
{
|
|
if ($this->isAjaxActionError()) {
|
|
return $this->exception->getMessage();
|
|
}
|
|
return parent::fetch();
|
|
}
|
|
|
|
protected function getTemplate()
|
|
{
|
|
return '/actions/' . $this->template;
|
|
}
|
|
|
|
protected function sendHttpCode()
|
|
{
|
|
if ($this->exception instanceof ErrorHTTPException) {
|
|
header($this->exception->getHTTPHeader());
|
|
} else {
|
|
header('HTTP/1.0 500 Internal Server Error');
|
|
}
|
|
}
|
|
|
|
protected function logError()
|
|
{
|
|
if (!$this->exception instanceof Error404Exception) {
|
|
ErrorHandler::logError($this->exception);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check, if exception was thrown from AjaxAction Class
|
|
* @return bool
|
|
*/
|
|
protected function isAjaxActionError()
|
|
{
|
|
return $this->ajax_error;
|
|
}
|
|
|
|
/**
|
|
* Set if exception was thrown from AjaxAction subclass
|
|
*/
|
|
public function setAjaxError()
|
|
{
|
|
$this->ajax_error = true;
|
|
}
|
|
}
|