diff --git a/src/main/php/web/frontend/CannotRoute.class.php b/src/main/php/web/frontend/CannotRoute.class.php new file mode 100755 index 0000000..c20cb61 --- /dev/null +++ b/src/main/php/web/frontend/CannotRoute.class.php @@ -0,0 +1,20 @@ +method= $method; + $this->path= $path; + } +} \ No newline at end of file diff --git a/src/main/php/web/frontend/Frontend.class.php b/src/main/php/web/frontend/Frontend.class.php index 8a3f674..e3980f9 100755 --- a/src/main/php/web/frontend/Frontend.class.php +++ b/src/main/php/web/frontend/Frontend.class.php @@ -85,7 +85,7 @@ private function view($req, $res, $delegate, $matches= []) { static $CSRF_EXEMPT= ['get' => true, 'head' => true]; if (null === $delegate) { - return $this->errors()->handle(new Error(404, 'Cannot route '.$req->method().' requests to '.$req->uri()->path())); + return $this->errors()->handle(new CannotRoute($req->method(), $req->uri()->path())); } // Verify CSRF token for anything which is not a GET or HEAD request diff --git a/src/test/php/web/frontend/unittest/HandlingTest.class.php b/src/test/php/web/frontend/unittest/HandlingTest.class.php index eb48cd3..f7b349e 100755 --- a/src/test/php/web/frontend/unittest/HandlingTest.class.php +++ b/src/test/php/web/frontend/unittest/HandlingTest.class.php @@ -4,7 +4,7 @@ use test\Assert; use test\{Expect, Test, TestCase, Values}; use web\frontend\unittest\actions\{Blogs, Home, Select, Users, Posts}; -use web\frontend\{Frontend, Templates, View}; +use web\frontend\{Frontend, Templates, View, CannotRoute}; use web\io\{TestInput, TestOutput}; use web\{Error, Request, Response}; @@ -172,7 +172,7 @@ public function write($template, $context, $out) { /* NOOP */ } Assert::equals(404, $res->status()); } - #[Test, Expect(class: Error::class, message: '/Cannot route PATCH requests to .+/')] + #[Test, Expect(class: CannotRoute::class, message: '/Cannot route PATCH requests to .+/')] public function unsupported_route() { $fixture= new Frontend(new Users(), new class() implements Templates { public function write($template, $context, $out) { /* NOOP */ }