4 * This file is (c) Copyright 2009 by Madhumita DHAR, Institut
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * This program has been developed in the frame of the HELIOS
22 * project with financial support of its funders.
28 // TODO: support the XML format for error messages (see http://open-services.net/bin/view/Main/CmRestApiV1)
30 class ErrorController extends Zend_Controller_Action
33 public function errorAction()
35 $errors = $this->_getParam('error_handler');
36 $contextSwitch = $this->_helper->getHelper('contextSwitch');
37 $contextSwitch->addActionContext($this->getRequest()->getActionName(), 'xml')->initContext();
38 $contextSwitch->addActionContext($this->getRequest()->getActionName(), 'json')->initContext();
40 switch ($errors->type) {
41 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
42 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
44 // 404 error -- controller or action not found
45 $this->getResponse()->setHttpResponseCode(404);
46 $this->view->message = 'Page not found';
50 //$this->getResponse()->setHttpResponseCode(500);
51 $this->view->message = 'Application error';
52 //print_r(get_class($errors->exception));
53 switch(get_class($errors->exception))
55 case 'ForbiddenException':
56 case 'NotAcceptableForCRCollectionException':
57 case 'BadRequestException':
58 case 'NotFoundException':
59 case 'ConflictException':
60 case 'UnsupportedMediaTypeException':
61 case 'NotAcceptableForSingleCRException':
63 case 'PreconditionFailedException':
64 //$this->_forward('res-not-found');
65 $this->getResponse()->setHttpResponseCode($errors->exception->getCode());
69 $this->getResponse()->setHttpResponseCode(500);
76 if($errors->exception->getCode()==0)
82 $return_code = $errors->exception->getCode();
85 $this->view->code = $return_code;
86 $this->view->exception = $errors->exception;
87 $this->view->request = $errors->request;
89 $this->getResponse()->setHeader('Content-Type', 'text/html');
92 public function resnotfoundAction()
94 $this->getResponse()->setHttpResponseCode(404);
95 $this->_forward('Default');
98 public function unknownaccepttypeAction()
100 $this->view->error_message = 'Unknown "Accept:" content-type';
101 $this->getResponse()->setHttpResponseCode(415);
102 $this->_forward('Default');
105 public function defaultAction()
107 $this->getResponse()->setHeader('Content-Type', 'text/html');