Skip to content

Commit 9411cdf

Browse files
committed
improve RouterMiddleware dealing with exceptions
- throws RouterException in case of the request method is not allowed
1 parent d4e30e8 commit 9411cdf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/Routing/RouterMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ public function __invoke(HttpContext $context, RequestDelegate $next)
3535
$context->Items->add('RouteHandler', $routeContext->Handler);
3636
$context->Request->RouteValues = $routeContext->RouteData->Values;
3737
} else {
38-
throw new RouterException("No route matches your request", 404);
38+
if (isset($routeContext->RouteData->Routers['forbidden'])) {
39+
throw new RouterException("The request method '{$context->Request->Method}' not allowed for the matched route!", 405);
40+
}
41+
throw new RouterException("No route matches your request!", 404);
3942
}
4043

4144
return $next($context);

0 commit comments

Comments
 (0)