diff --git a/src/Pecee/SimpleRouter/RouterBase.php b/src/Pecee/SimpleRouter/RouterBase.php index 8f58016..10f782b 100644 --- a/src/Pecee/SimpleRouter/RouterBase.php +++ b/src/Pecee/SimpleRouter/RouterBase.php @@ -89,9 +89,9 @@ class RouterBase { $route->renderRoute($this->request); $mergedSettings = array_merge($settings, $route->getMergeableSettings()); - // Add exceptionhandler + // Add ExceptionHandler if($route->matchRoute($this->request) && $route->getExceptionHandler() !== null) { - $this->exceptionHandlers[] = $route->getExceptionHandler(); + $this->exceptionHandlers[] = $route; } } @@ -178,8 +178,12 @@ class RouterBase { protected function handleException(\Exception $e) { - foreach ($this->exceptionHandlers as $handler) { - $handler = new $handler($this->request); + /* @var $route RouterEntry */ + foreach ($this->exceptionHandlers as $route) { + $route->loadMiddleware($this->request); + $handler = $route->getExceptionHandler(); + $handler = new $handler(); + if (!($handler instanceof IExceptionHandler)) { throw new RouterException('Exception handler must implement the IExceptionHandler interface.'); }