Skip to content

Commit

Permalink
[9.x] Improved error logging for unmatched routes and route not found (
Browse files Browse the repository at this point in the history
…#45206)

* Improved error logging for unmatched routes and route not found

* Update AbstractRouteCollection.php

* Update AbstractRouteCollection.php

* Update AbstractRouteCollection.php
  • Loading branch information
i386 committed Dec 7, 2022
1 parent cad86c1 commit 5fae417
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/Illuminate/Routing/AbstractRouteCollection.php
Expand Up @@ -41,7 +41,10 @@ protected function handleMatchedRoute(Request $request, $route)
return $this->getRouteForMethods($request, $others);
}

throw new NotFoundHttpException;
throw new NotFoundHttpException(sprintf(
'The route %s could not be found.',
$request->path()
));
}

/**
Expand Down Expand Up @@ -101,7 +104,30 @@ protected function getRouteForMethods($request, array $methods)
}))->bind($request);
}

$this->methodNotAllowed($methods, $request->method());
$this->requestMethodNotAllowed($request, $methods, $request->method());
}

/**
* Throw a method not allowed HTTP exception.
*
* @param \Illuminate\Http\Request $request
* @param array $others
* @param string $method
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function requestMethodNotAllowed($request, array $others, $method)
{
throw new MethodNotAllowedHttpException(
$others,
sprintf(
'The %s method is not supported for route %s. Supported methods: %s.',
$request->path(),
$method,
implode(', ', $others)
)
);
}

/**
Expand All @@ -110,6 +136,7 @@ protected function getRouteForMethods($request, array $methods)
* @param array $others
* @param string $method
* @return void
* @deprecated use requestMethodNotAllowed
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
Expand Down

0 comments on commit 5fae417

Please sign in to comment.