From 80721ed22ec738cc604ee4c8a80c38097b71d9c1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 9 Apr 2022 19:09:45 +0900 Subject: [PATCH] refactor: improve exception messages --- system/Router/AutoRouterImproved.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/system/Router/AutoRouterImproved.php b/system/Router/AutoRouterImproved.php index 324d02caa6de..219faeb23e1d 100644 --- a/system/Router/AutoRouterImproved.php +++ b/system/Router/AutoRouterImproved.php @@ -127,7 +127,9 @@ public function getRoute(string $uri): array strtolower($baseControllerName) === strtolower($this->defaultController) && strtolower($controllerSegment) === strtolower($this->defaultController) ) { - throw PageNotFoundException::forPageNotFound(); + throw new PageNotFoundException( + 'Cannot access the default controller "' . $baseControllerName . '" with the controller name URI path.' + ); } // Use the method name if it exists. @@ -139,7 +141,9 @@ public function getRoute(string $uri): array // Prevent access to default method path if (strtolower($this->method) === strtolower($this->defaultMethod)) { - throw PageNotFoundException::forPageNotFound(); + throw new PageNotFoundException( + 'Cannot access the default method "' . $this->method . '" with the method name URI path.' + ); } } @@ -164,16 +168,20 @@ public function getRoute(string $uri): array foreach ($this->collection->getRoutes('cli') as $route) { if (is_string($route)) { - $route = strtolower($route); + $routeLowerCase = strtolower($route); if (strpos( - $route, + $routeLowerCase, $controller . '::' . $methodName ) === 0) { - throw new PageNotFoundException(); + throw new PageNotFoundException( + 'Cannot access CLI Route Handler: ' . $route + ); } - if ($route === $controller) { - throw new PageNotFoundException(); + if ($routeLowerCase === $controller) { + throw new PageNotFoundException( + 'Cannot access cli route: ' . $route + ); } } }