@@ -116,11 +116,15 @@ public function setDefaults(array $defaults)
116116 */
117117 public function dispatch ($ uri = null )
118118 {
119+ $ httpMethod = $ this ->getRequestMethod ();
120+ if (empty ($ uri )) {
121+ $ uri = $ this ->getRewriteUri ();
122+ }
123+
119124 $ this ->handleDispatcherResponse (
120- $ this ->createDispatcher ()->dispatch (
121- $ this ->getRequestMethod (),
122- $ uri ?: $ this ->getRewriteUri ()
123- )
125+ $ this ->createDispatcher ()->dispatch ($ httpMethod , $ uri ),
126+ $ httpMethod ,
127+ $ uri
124128 );
125129 }
126130
@@ -146,16 +150,18 @@ protected function createDispatcher()
146150 * Handle the response from the FastRoute dispatcher.
147151 *
148152 * @param array $routeInfo
153+ * @param string $httpMethod
154+ * @param string $uri
149155 * @throws Exception
150156 */
151- protected function handleDispatcherResponse ($ routeInfo )
157+ protected function handleDispatcherResponse ($ routeInfo, $ httpMethod , $ uri )
152158 {
153159 if ($ routeInfo [0 ] == \FastRoute \Dispatcher::NOT_FOUND ) {
154- throw new Exception (' Not found handler ' );
160+ throw new Exception (" Not found handler: $ uri " , 404 );
155161 }
156162 if ($ routeInfo [0 ] == \FastRoute \Dispatcher::METHOD_NOT_ALLOWED ) {
157163 $ allowed = (array )$ routeInfo [1 ];
158- throw new Exception (' Method Not Allowed, allowed: ' . implode (', ' , $ allowed ));
164+ throw new Exception (" Method Not Allowed: $ uri , allowed: " . implode (', ' , $ allowed ), 405 );
159165 }
160166
161167 // \FastRoute\Dispatcher::FOUND
0 commit comments