Skip to content

Commit 5fae417

Browse files
author
James William Dumay
authored
[9.x] Improved error logging for unmatched routes and route not found (#45206)
* Improved error logging for unmatched routes and route not found * Update AbstractRouteCollection.php * Update AbstractRouteCollection.php * Update AbstractRouteCollection.php
1 parent cad86c1 commit 5fae417

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/Illuminate/Routing/AbstractRouteCollection.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ protected function handleMatchedRoute(Request $request, $route)
4141
return $this->getRouteForMethods($request, $others);
4242
}
4343

44-
throw new NotFoundHttpException;
44+
throw new NotFoundHttpException(sprintf(
45+
'The route %s could not be found.',
46+
$request->path()
47+
));
4548
}
4649

4750
/**
@@ -101,7 +104,30 @@ protected function getRouteForMethods($request, array $methods)
101104
}))->bind($request);
102105
}
103106

104-
$this->methodNotAllowed($methods, $request->method());
107+
$this->requestMethodNotAllowed($request, $methods, $request->method());
108+
}
109+
110+
/**
111+
* Throw a method not allowed HTTP exception.
112+
*
113+
* @param \Illuminate\Http\Request $request
114+
* @param array $others
115+
* @param string $method
116+
* @return void
117+
*
118+
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
119+
*/
120+
protected function requestMethodNotAllowed($request, array $others, $method)
121+
{
122+
throw new MethodNotAllowedHttpException(
123+
$others,
124+
sprintf(
125+
'The %s method is not supported for route %s. Supported methods: %s.',
126+
$request->path(),
127+
$method,
128+
implode(', ', $others)
129+
)
130+
);
105131
}
106132

107133
/**
@@ -110,6 +136,7 @@ protected function getRouteForMethods($request, array $methods)
110136
* @param array $others
111137
* @param string $method
112138
* @return void
139+
* @deprecated use requestMethodNotAllowed
113140
*
114141
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
115142
*/

0 commit comments

Comments
 (0)