Skip to content

Commit 3868acb

Browse files
authored
Merge pull request #5984 from kenjis/feat-Router-exception-message
improve Router Exception message
2 parents 14dea5c + 557ba27 commit 3868acb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

system/Router/Router.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ public function handle(?string $uri = null)
196196
// Controllers/directories, but the application may not
197197
// want this, like in the case of API's.
198198
if (! $this->collection->shouldAutoRoute()) {
199-
throw new PageNotFoundException("Can't find a route for '{$uri}'.");
199+
throw new PageNotFoundException(
200+
"Can't find a route for '{$this->collection->getHTTPVerb()}: {$uri}'."
201+
);
200202
}
201203

202204
// Checks auto routes

tests/system/Router/RouterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ public function testAutoRouteRejectsInitController()
384384
$router->autoRoute('home/initController');
385385
}
386386

387+
public function testExceptionMessageWhenRouteNotFound()
388+
{
389+
$router = new Router($this->collection, $this->request);
390+
391+
$this->expectException(PageNotFoundException::class);
392+
$this->expectExceptionMessage("Can't find a route for 'get: url/not-exists'");
393+
394+
$router->handle('url/not-exists');
395+
}
396+
387397
public function testDetectsLocales()
388398
{
389399
$router = new Router($this->collection, $this->request);

0 commit comments

Comments
 (0)