You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the router throws a RouteNotFoundException either if it doesn't find a route with a matching pattern or a matching method. My suggestion is to introduce either a property on RouteNotFoundException or a new MethodMismatchException to differentiate between a 404 Not Found and a 405 Method Not Allowed error.
Example:
<?phpuseMiladRahimi\PhpRouter\Router;
useLaminas\Diactoros\Response\HtmlResponse;
useMiladRahimi\PhpRouter\Exceptions\RouteNotFoundException;
require__DIR__ . "/vendor/autoload.php";
$router = Router::create();
$router->get('/', function() use ($twig) {
returnnewHtmlResponse("<h1>Test</h1>\n");
});
try {
$router->dispatch();
} catch (RouteNotFoundException$ex) {
// We have no way to tell if it really is a 404 or 405 error...$router->getPublisher()->publish(newHtmlResponse('Not found.', 404));
} catch (\Throwable$e) {
$router->getPublisher()->publish(newHtmlResponse('Internal error.', 500));
}
If we POST http://<DOMAIN>/ we get a HTTP/1.1 404 Not Found, despite it actually resembeling a 405 error.
Currently the router throws a
RouteNotFoundException
either if it doesn't find a route with a matching pattern or a matching method. My suggestion is to introduce either a property onRouteNotFoundException
or a newMethodMismatchException
to differentiate between a404 Not Found
and a405 Method Not Allowed
error.Example:
If we
POST http://<DOMAIN>/
we get aHTTP/1.1 404 Not Found
, despite it actually resembeling a 405 error.Proposal:
If we now
POST http://<DOMAIN>/
we correctly get aHTTP/1.1 405 Method Not Allowed
.The text was updated successfully, but these errors were encountered: