コード例 #1
1
 /**
  * Make sure the code value is returned as a string
  * // FIXME make this configurable via an option
  *
  * @param \Exception $exception Exception
  * @return string Error code value within range 400 to 506
  */
 protected function _code(\Exception $exception)
 {
     return (string) parent::_code($exception);
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 protected function _template(\Exception $exception, $method, $code)
 {
     if ($code === 503) {
         return 'maintenance';
     }
     return parent::_template($exception, $method, $code);
 }
コード例 #3
0
 public function render()
 {
     $code = $this->_code($this->error);
     if ($code == 404) {
         $this->controller->redirect('/pagina-nao-encontrada');
     }
     return parent::render();
 }
コード例 #4
0
 /**
  * Make CrudView exception rendering templates work
  * 
  * @param \CrudViews\Error\Exception $exception
  * @param type $method
  * @param type $code
  * @return string
  */
 protected function _template(Exception $exception, $method, $code)
 {
     parent::_template($exception, $method, $code);
     if (in_array($this->template, $this->_exceptions)) {
         $this->template = 'CrudViews.' . $this->template;
     }
     return $this->template;
 }
コード例 #5
0
 /**
  * Generate the response using the controller object.
  *
  * If there is no specific template for the raised error (normally there won't be one)
  * swallow the missing view exception and just use the standard
  * error format. This prevents throwing an unknown Exception and seeing instead
  * a MissingView exception
  *
  * @param string $template The template to render.
  * @return \Cake\Network\Response
  */
 protected function _outputMessage($template)
 {
     $viewVars = ['success', 'data'];
     $this->controller->set('success', false);
     $this->controller->set('data', $this->_getErrorData());
     if (Configure::read('debug')) {
         $queryLog = $this->_getQueryLog();
         if ($queryLog) {
             $this->controller->set(compact('queryLog'));
             $viewVars[] = 'queryLog';
         }
     }
     $this->controller->set('_serialize', $viewVars);
     return parent::_outputMessage($template);
 }
コード例 #6
0
 /**
  * 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 = ['seven' => 7];
     $ExceptionRenderer = new ExceptionRenderer($exception);
     $ExceptionRenderer->controller->response = $this->getMock('Cake\\Network\\Response', ['statusCode', '_sendHeader']);
     $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);
     $result = $ExceptionRenderer->render()->body();
     $this->assertContains('Database Error', $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);
 }
コード例 #7
0
 public function render()
 {
     $this->controller->helpers = ['Html' => ['className' => 'Bootstrap.BootstrapHtml', 'useFontAwesome' => true], 'Form' => ['className' => 'Bootstrap.BootstrapForm'], 'Paginator' => ['className' => 'Bootstrap.BootstrapPaginator'], 'Modal' => ['className' => 'Bootstrap.BootstrapModal'], 'AssetCompress.AssetCompress'];
     return parent::render();
 }