2 /* This file is part of Syj, Copyright (c) 2010-2011 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->_helper->SyjMedias->addStyleSheets('error');
16 public function errorAction() {
17 $error = $this->_getParam('error_handler');
19 $error_code = 500; // default value: Internal Server Error
20 switch ($error->type) {
21 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
22 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
23 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
24 $error_code = 404; // Not Found
27 if ($error->exception instanceof Syj_Exception_Request) {
28 $error_code = 400; // Bad Request
29 } else if ($error->exception instanceof Syj_Exception_Forbidden) {
30 $error_code = 403; // Forbidden
31 } else if ($error->exception instanceof Syj_Exception_NotFound) {
32 $error_code = $error->exception->getCode();
36 $this->httpError($error_code);
38 // Log exception, if logger available
39 if ($log = $this->getLog()) {
40 $log->crit($this->view->message, $error->exception);
43 if ($error_code == 400 and $error->request->isXmlHttpRequest()) {
44 return $this->_helper->json(array('message' => $error->exception->getMessage()));
45 } else if ($error->exception instanceof Syj_Exception_InvalidGeomUpload) {
46 // invalid file upload: we will redirect to main page
47 $this->_helper->SyjReset->resetPlaceHolders();
48 $this->_request->setControllerName('idx')->setActionName('error')->setDispatched(false);
52 // conditionally display exceptions
53 if ($this->getInvokeArg('displayExceptions') == true) {
54 $this->view->exception = $error->exception;
57 $this->view->request = $error->request;
58 $this->view->isServerError = ($error_code >= 500 and $error_code < 600);
59 $this->view->headTitle($this->view->translate("Oups, something went wrong"));
62 public function getLog() {
63 $bootstrap = $this->getInvokeArg('bootstrap');
64 if (!$bootstrap->hasPluginResource('Log')) {
67 $log = $bootstrap->getResource('Log');