2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class ErrorController extends Zend_Controller_Action
7 protected function httpError($code) {
8 $this->getResponse()->setHttpResponseCode($code);
11 public function init() {
12 $this->_helper->SyjReset->resetPlaceHolders();
13 $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
14 $this->view->headLink()->appendStylesheet('css/error.css', 'all');
17 public function errorAction() {
18 $error = $this->_getParam('error_handler');
20 $error_code = 500; // default value: Internal Server Error
21 switch ($error->type) {
22 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
23 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
24 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
25 $error_code = 404; // Not Found
28 if ($error->exception instanceof Syj_Exception_Request) {
29 $error_code = 400; // Bad Request
30 } else if ($error->exception instanceof Syj_Exception_Forbidden) {
31 $error_code = 403; // Forbidden
32 } else if ($error->exception instanceof Syj_Exception_NotFound) {
33 $error_code = $error->exception->getCode();
37 $this->httpError($error_code);
39 // Log exception, if logger available
40 if ($log = $this->getLog()) {
41 $log->crit($this->view->message, $error->exception);
44 if ($error_code == 400 and $error->request->isXmlHttpRequest()) {
45 return $this->_helper->json(array('message' => $error->exception->getMessage()));
46 } else if ($error->exception instanceof Syj_Exception_InvalidGeomUpload) {
47 // invalid file upload: we will redirect to main page
48 $this->_helper->SyjReset->resetPlaceHolders();
49 $this->_request->setControllerName('idx')->setActionName('error')->setDispatched(false);
53 // conditionally display exceptions
54 if ($this->getInvokeArg('displayExceptions') == true) {
55 $this->view->exception = $error->exception;
58 $this->view->request = $error->request;
59 $this->view->isServerError = ($error_code >= 500 and $error_code < 600);
60 $this->view->headTitle($this->view->translate("Oups, something went wrong"));
63 public function getLog() {
64 $bootstrap = $this->getInvokeArg('bootstrap');
65 if (!$bootstrap->hasPluginResource('Log')) {
68 $log = $bootstrap->getResource('Log');