diff --git a/src/Error/ExceptionRenderer.php b/src/Error/ExceptionRenderer.php index da279c3f4f2..8a643291ae0 100644 --- a/src/Error/ExceptionRenderer.php +++ b/src/Error/ExceptionRenderer.php @@ -191,10 +191,7 @@ public function render() $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 @@ public function render() 'code' => $code, '_serialize' => ['message', 'url', 'code'] ]; + + $isDebug = Configure::read('debug'); if ($isDebug) { $viewVars['trace'] = Debugger::formatTrace($unwrapped->getTrace(), [ 'format' => 'array', diff --git a/tests/TestCase/Error/ExceptionRendererTest.php b/tests/TestCase/Error/ExceptionRendererTest.php index 240d50090bf..a81386a2558 100644 --- a/tests/TestCase/Error/ExceptionRendererTest.php +++ b/tests/TestCase/Error/ExceptionRendererTest.php @@ -727,6 +727,13 @@ public function testExceptionNameMangling() $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); } /**