diff --git a/src/Error/ExceptionRenderer.php b/src/Error/ExceptionRenderer.php index dfb51c5c052..08596d09df6 100644 --- a/src/Error/ExceptionRenderer.php +++ b/src/Error/ExceptionRenderer.php @@ -170,7 +170,7 @@ public function render() $message = $this->_message($exception, $code); $url = $this->controller->request->getRequestTarget(); - if (method_exists($exception, 'responseHeader')) { + if ($exception instanceof CakeException) { $this->controller->response->header($exception->responseHeader()); } $this->controller->response->statusCode($code); diff --git a/src/Error/Middleware/ErrorHandlerMiddleware.php b/src/Error/Middleware/ErrorHandlerMiddleware.php index f1cdcef4b83..eae164ec4a7 100644 --- a/src/Error/Middleware/ErrorHandlerMiddleware.php +++ b/src/Error/Middleware/ErrorHandlerMiddleware.php @@ -16,6 +16,7 @@ use Cake\Core\App; use Cake\Core\Configure; +use Cake\Core\Exception\Exception as CakeException; use Cake\Core\InstanceConfigTrait; use Cake\Error\ExceptionRenderer; use Cake\Log\Log; @@ -90,7 +91,7 @@ public function __invoke($request, $response, $next) { try { return $next($request, $response); - } catch (\Exception $e) { + } catch (Exception $e) { return $this->handleException($e, $request, $response); } } @@ -111,7 +112,7 @@ public function handleException($exception, $request, $response) $this->logException($request, $exception); return $res; - } catch (\Exception $e) { + } catch (Exception $e) { $this->logException($request, $e); $body = $response->getBody(); @@ -193,7 +194,7 @@ protected function getMessage($request, $exception) ); $debug = Configure::read('debug'); - if ($debug && method_exists($exception, 'getAttributes')) { + if ($debug && $exception instanceof CakeException) { $attributes = $exception->getAttributes(); if ($attributes) { $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);