Handle API requests in the ErrorController

refs #9606
This commit is contained in:
Eric Lippmann 2015-08-20 15:49:37 +02:00
parent dd23bd9397
commit e914b733cd

View File

@ -14,6 +14,9 @@ use Icinga\Web\Controller\ActionController;
*/ */
class ErrorController extends ActionController class ErrorController extends ActionController
{ {
/**
* {@inheritdoc}
*/
protected $requiresAuthentication = false; protected $requiresAuthentication = false;
/** /**
@ -23,7 +26,7 @@ class ErrorController extends ActionController
{ {
$error = $this->_getParam('error_handler'); $error = $this->_getParam('error_handler');
$exception = $error->exception; $exception = $error->exception;
/** @var \Exception $exception */
Logger::error($exception); Logger::error($exception);
Logger::error('Stacktrace: %s', $exception->getTraceAsString()); Logger::error('Stacktrace: %s', $exception->getTraceAsString());
@ -74,6 +77,15 @@ class ErrorController extends ActionController
} }
break; break;
} }
if ($this->getRequest()->getIsApiRequest()) {
// @TODO(el): Use ApiResponse class for unified response handling.
$this->getRequest()->sendJson(array(
'status' => 'error',
'message' => $this->view->message
));
}
$this->view->request = $error->request; $this->view->request = $error->request;
} }
} }