diff --git a/src/RouterEngine.php b/src/RouterEngine.php index e6432f8..f9f0b51 100644 --- a/src/RouterEngine.php +++ b/src/RouterEngine.php @@ -66,7 +66,7 @@ class RouterEngine /** * Stores if not found error occured */ - private $not_found; + private $not_found = false; //---------------------------------------------------------------// @@ -88,12 +88,13 @@ public function __construct(Request $request, RouteCollection $collection, $apiM */ public function route() { + try{ // Get URL and request method. $this->request_method = strtolower($this->request->getMethod()); if ($this->check_manual()) { - return; + return true; } //Break URL into segments @@ -109,11 +110,16 @@ public function route() $this->request->attributes->set('_controller', $this->controller . '::' . $this->method); $this->setArguments(); - - if($this->not_found) return true; - else - return false; + } catch(\Exception $e){ + if($this->apiMode){ + return false; + }else{ + throw $e; + } + } + + } //---------------------------------------------------------------// @@ -181,8 +187,6 @@ private function getController() protected function error($message) { $this->not_found = true; - - if(!$this->apiMode) throw new NotFoundException('Oops its an 404 error! :' . $message); } @@ -196,7 +200,7 @@ protected function error($message) private function setArguments() { $controller = new $this->controller; - + $arguments = []; for ($j = 2; $j < count($this->path_info); $j++) { array_push($arguments, $this->path_info[$j]);