Skip to content

Commit

Permalink
Always call custom exception renderer method.
Browse files Browse the repository at this point in the history
Closes #9905.
  • Loading branch information
ADmad committed Aug 25, 2018
1 parent 394ddc3 commit 7a7eed8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Error/ExceptionRenderer.php
Expand Up @@ -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);
}

Expand All @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 7a7eed8

Please sign in to comment.