Browse Source

Modified handling of Error404Exception for AjaxAction-based classes

master
Anton Terekhov 14 years ago
parent
commit
d93edd1ea7
  1. 25
      app/ErrorAction.php

25
app/ErrorAction.php

@ -27,6 +27,12 @@ class ErrorAction extends Action
{
$this->template = 500;
if ($this->exception instanceof Error404Exception) {
if ($this->isAjaxActionError()) {
if (!headers_sent()) {
header('HTTP/1.0 404 Not Found');
die();
}
}
$this->template = 404;
}
$this->logError();
@ -76,9 +82,24 @@ class ErrorAction extends Action
$error = 'Unknown Error';
break;
}
$message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile()
. ' on line ' . $ex->getLine();
$message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile()
. ' on line ' . $ex->getLine();
error_log($message);
}
}
/**
* Check, if exception was thrown from AjaxAction Class
* @return bool
*/
protected function isAjaxActionError()
{
$trace = $this->exception->getTrace();
foreach ($trace as $line) {
if (isset($line['class']) && $line['class'] === 'AjaxAction') {
return true;
}
}
return false;
}
}
Loading…
Cancel
Save