Browse Source

Merge pull request #12500 from cakephp/3.7-exception-renderer-custom-method

Always call custom exception renderer method.
Mark Story 7 years ago
parent
commit
589100a27f
2 changed files with 10 additions and 4 deletions
  1. 3 4
      src/Error/ExceptionRenderer.php
  2. 7 0
      tests/TestCase/Error/ExceptionRendererTest.php

+ 3 - 4
src/Error/ExceptionRenderer.php

@@ -191,10 +191,7 @@ class ExceptionRenderer implements ExceptionRendererInterface
         $template = $this->_template($exception, $method, $code);
         $unwrapped = $this->_unwrap($exception);
 
-        $isDebug = Configure::read('debug');
-        if (($isDebug || $exception instanceof HttpException) &&
-            method_exists($this, $method)
-        ) {
+        if (method_exists($this, $method)) {
             return $this->_customMethod($method, $unwrapped);
         }
 
@@ -216,6 +213,8 @@ class ExceptionRenderer implements ExceptionRendererInterface
             'code' => $code,
             '_serialize' => ['message', 'url', 'code']
         ];
+
+        $isDebug = Configure::read('debug');
         if ($isDebug) {
             $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), [
                 'format' => 'array',

+ 7 - 0
tests/TestCase/Error/ExceptionRendererTest.php

@@ -733,6 +733,13 @@ class ExceptionRendererTest extends TestCase
 
         $result = (string)$exceptionRenderer->render()->getBody();
         $this->assertContains('widget thing is missing', $result);
+
+        // Custom method should be called even when debug is off.
+        Configure::write('debug', false);
+        $exceptionRenderer = new MyCustomExceptionRenderer(new MissingWidgetThing());
+
+        $result = (string)$exceptionRenderer->render()->getBody();
+        $this->assertContains('widget thing is missing', $result);
     }
 
     /**