From a0402f1994608f261a76dacc3b578e8443a70e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Fri, 11 Mar 2016 00:01:19 +0100 Subject: [PATCH] throw exception instead of return Response --- src/Server.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Server.php b/src/Server.php index 9d328d3c..13765727 100644 --- a/src/Server.php +++ b/src/Server.php @@ -128,7 +128,8 @@ class Server implements EmitterAwareInterface } $tokenResponse = null; - foreach ($this->enabledGrantTypes as $grantType) { + while ($tokenResponse === null && $grantType = array_shift($this->enabledGrantTypes)) { + /** @var \League\OAuth2\Server\Grant\GrantTypeInterface $grantType */ if ($grantType->canRespondToRequest($request)) { $tokenResponse = $grantType->respondToRequest( $request, @@ -142,11 +143,11 @@ class Server implements EmitterAwareInterface return $tokenResponse; } - if ($tokenResponse instanceof ResponseTypeInterface === false) { - return OAuthServerException::unsupportedGrantType()->generateHttpResponse($response); + if ($tokenResponse instanceof ResponseTypeInterface) { + return $tokenResponse->generateHttpResponse($response); } - return $tokenResponse->generateHttpResponse($response); + throw OAuthServerException::unsupportedGrantType(); } /**