public function error500($error) { if (Router::currentRoute()->defaults['plugin'] == 'api') { $this->controller->viewClass = 'Json'; } parent::error500($error); }
public function render() { $this->controller->set('title_for_layout', __('Error!')); if (TEST_ENV) { parent::render(); } else { if ($this->method !== 'error500') { $this->method = 'error400'; } parent::render(); } }
public function render() { $this->controller->set('title_for_layout', __('Error!')); if (Configure::read('debug') == 2) { parent::render(); } else { if ($this->method !== 'error500') { $this->method = 'error400'; } parent::render(); } }
/** * Get a custom InfinitasErrorController instance * * This instance tries to load up the very minimum to display the error * page. If anything goes wrong it falls back to the default CakeErrorController * * @param Exception $exception The exception to get a controller for. * * @return Controller */ protected function _getController($exception) { App::uses('InfinitasErrorController', 'Controller'); if (!($request = Router::getRequest(true))) { $request = new CakeRequest(); } $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); try { return new InfinitasErrorController($request, $response); } catch (Exception $e) { return parent::_getController($exception); } }
/** * Get the controller instance to handle the exception. * Override this method in subclasses to customize the controller used. * This method returns the built in `CakeErrorController` normally, or if an error is repeated * a bare controller will be used. * * @param Exception $exception The exception to get a controller for. * @return Controller */ protected function _getController($exception) { if (!($request = Router::getRequest(true))) { $request = new CakeRequest(); } // If outside of plugin, use default handling if ($request->params['plugin'] !== 'forum') { return parent::_getController($exception); } $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); $controller = new ForumAppController($request, $response); $controller->viewPath = 'Errors'; $controller->constructClasses(); $controller->startupProcess(); return $controller; }
public function render() { if ($this->error instanceof MP\ApiConnectionException) { $url = $this->controller->request->here(); $code = 500; $this->controller->response->statusCode($code); $this->controller->set(array('code' => $code, 'url' => h($url), 'name' => h($this->error->getMessage()), 'error' => $this->error, '_serialize' => array('code', 'url', 'name', 'error'))); $this->template = str_replace('mP\\', 'mp/', $this->template); $this->_outputMessage($this->template); } elseif ($this->error instanceof MissingControllerException) { if (is_numeric($this->controller->request->params['action'])) { $url = '/dane' . $this->controller->request->here(); $this->controller->redirect($url); } else { return parent::render(); } } else { return parent::render(); } }
/** * Test that exceptions can be rendered when an request hasn't been registered * with Router * * @return void */ public function testRenderWithNoRequest() { Router::reload(); $this->assertNull(Router::getRequest(false)); $exception = new Exception('Terrible'); $ExceptionRenderer = new ExceptionRenderer($exception); $ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader')); $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500); ob_start(); $ExceptionRenderer->render(); $result = ob_get_clean(); $this->assertContains('Internal Error', $result); }
/** * Tests the output of rendering a PDOException * * @return void */ public function testPDOException() { $exception = new PDOException('There was an error in the SQL query'); $exception->queryString = 'SELECT * from poo_query < 5 and :seven'; $exception->params = array('seven' => 7); $ExceptionRenderer = new ExceptionRenderer($exception); $ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader')); $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500); ob_start(); $ExceptionRenderer->render(); $result = ob_get_clean(); $this->assertContains('<h2>Database Error</h2>', $result); $this->assertContains('There was an error in the SQL query', $result); $this->assertContains(h('SELECT * from poo_query < 5 and :seven'), $result); $this->assertContains("'seven' => (int) 7", $result); }
/** * Test that rendering exceptions triggers shutdown events. * * @return void */ public function testRenderShutdownEvents() { $fired = array(); $listener = function ($event) use(&$fired) { $fired[] = $event->name(); }; $EventManager = CakeEventManager::instance(); $EventManager->attach($listener, 'Controller.shutdown'); $EventManager->attach($listener, 'Dispatcher.afterDispatch'); $exception = new Exception('Terrible'); $ExceptionRenderer = new ExceptionRenderer($exception); ob_start(); $ExceptionRenderer->render(); ob_get_clean(); $expected = array('Controller.shutdown', 'Dispatcher.afterDispatch'); $this->assertEquals($expected, $fired); }
/** * construct a new instance of this class * * @param Exception $exception the exception being thrown */ public function __construct(Exception $exception) { parent::__construct($exception); }
/** * Test the various CakeException sub classes * * @dataProvider testProvider * @return void */ function testCakeExceptionHandling($exception, $patterns, $code) { $ExceptionRenderer = new ExceptionRenderer($exception); $ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader')); $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with($code); ob_start(); $ExceptionRenderer->render(); $result = ob_get_clean(); foreach ($patterns as $pattern) { $this->assertPattern($pattern, $result); } }