Skip to content

Commit 0348688

Browse files
committed
Merge pull request dingo#283 from Andreyco/master
Throw an Exception for invalid API version
2 parents e26142c + 09c0814 commit 0348688

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Routing/Router.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Http\Response as IlluminateResponse;
1717
use Dingo\Api\Exception\InvalidAcceptHeaderException;
1818
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1920
use Illuminate\Routing\RouteCollection as IlluminateRouteCollection;
2021
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
2122

@@ -341,11 +342,17 @@ protected function attachApiFilters(Route $route)
341342
protected function findRoute($request)
342343
{
343344
if ($this->isApiRequest($request)) {
344-
$route = $this->api->getByVersion($this->currentVersion)->match($request);
345+
$routes = $this->api->getByVersion($this->currentVersion);
345346
} else {
346-
$route = $this->routes->match($request);
347+
$routes = $this->routes;
347348
}
348349

350+
if (! $routes) {
351+
throw new BadRequestHttpException("Requested API version is invalid.");
352+
}
353+
354+
$route = $routes->match($request);
355+
349356
return $this->current = $this->substituteBindings($route);
350357
}
351358

0 commit comments

Comments
 (0)