From 41705f030a997e240d99d70e8685153596f6485f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sat, 7 Oct 2017 12:33:24 +0100 Subject: [PATCH] Fixed: try next exception-handler if one throws error. --- src/Pecee/SimpleRouter/Router.php | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php index 8144a95..a80073b 100644 --- a/src/Pecee/SimpleRouter/Router.php +++ b/src/Pecee/SimpleRouter/Router.php @@ -329,25 +329,31 @@ class Router throw new HttpException('Exception handler must implement the IExceptionHandler interface.', 500); } - if ($handler->handleError($this->request, $e) !== null) { + try { - $rewriteRoute = $this->request->getRewriteRoute(); + if ($handler->handleError($this->request, $e) !== null) { - if ($rewriteRoute !== null) { - $rewriteRoute->loadMiddleware($this->request); + $rewriteRoute = $this->request->getRewriteRoute(); - return $rewriteRoute->renderRoute($this->request); + if ($rewriteRoute !== null) { + $rewriteRoute->loadMiddleware($this->request); + + return $rewriteRoute->renderRoute($this->request); + } + + $rewriteUrl = $this->request->getRewriteUrl(); + + /* If the request has changed */ + if ($rewriteUrl !== null && $rewriteUrl !== $url) { + unset($this->exceptionHandlers[$i]); + $this->exceptionHandlers = array_values($this->exceptionHandlers); + + return $this->routeRequest(true); + } } - $rewriteUrl = $this->request->getRewriteUrl(); + } catch (\Exception $e) { - /* If the request has changed */ - if ($rewriteUrl !== null && $rewriteUrl !== $url) { - unset($this->exceptionHandlers[$i]); - $this->exceptionHandlers = array_values($this->exceptionHandlers); - - return $this->routeRequest(true); - } } }