Skip to content

Commit

Permalink
refactor: improve exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 9, 2022
1 parent c12b31f commit 80721ed
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.'
);
}
}

Expand All @@ -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
);
}
}
}
Expand Down

0 comments on commit 80721ed

Please sign in to comment.