File indexing completed on 2024-03-24 05:57:21

0001 <?php
0002 /**
0003  *
0004  *   ocs-apiserver
0005  *
0006  *   Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-apiserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  *
0023  */
0024 
0025 class ErrorController extends Zend_Controller_Action
0026 {
0027 
0028     public function errorAction()
0029     {
0030         $errors = $this->_getParam('error_handler');
0031         
0032         if (!$errors) {
0033             $message = 'You have reached the error page';
0034             return;
0035         }
0036         
0037         switch ($errors->type) {
0038             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
0039             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
0040             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
0041                 // 404 error -- controller or action not found
0042                 $this->getResponse()->setHttpResponseCode(404);
0043                 $priority = Zend_Log::NOTICE;
0044                 $message = 'Page not found';
0045                 break;
0046             default:
0047                 // application error
0048                 $this->getResponse()->setHttpResponseCode(500);
0049                 $priority = Zend_Log::CRIT;
0050                 $message = 'Application error';
0051                 break;
0052         }
0053         
0054         // Log exception, if logger available
0055         if ($log = $this->getLog()) {
0056             $log->log($message, $priority, $errors->exception);
0057             $log->crit($errors->exception);
0058             $log->log('Request Parameters', $priority, $errors->request->getParams());
0059             $log->crit(print_r($errors->request->getParams(), true));
0060         }
0061         
0062         // conditionally display exceptions
0063         if ($this->getInvokeArg('displayExceptions') == true) {
0064             $exception = $errors->exception;
0065         }
0066         
0067         $request   = $errors->request;
0068 
0069         $this->getResponse()->setHttpResponseCode(500);
0070         $this->getResponse()->setBody(json_encode(array($message,$errors)));
0071     }
0072 
0073     /**
0074      * @return Zend_Log
0075      * @throws Zend_Exception
0076      */
0077     public function getLog()
0078     {
0079         //$bootstrap = $this->getInvokeArg('bootstrap');
0080         //if (!$bootstrap->hasResource('Log')) {
0081         //    return false;
0082         //}
0083         //$log = $bootstrap->getResource('Log');
0084         //return $log;
0085         return Zend_Registry::get('logger');
0086     }
0087 
0088 
0089 }
0090