diff --git a/src/Providers/Coding.php b/src/Providers/Coding.php index 4ab71d9..d9ac5df 100644 --- a/src/Providers/Coding.php +++ b/src/Providers/Coding.php @@ -7,6 +7,7 @@ use Overtrue\Socialite\Contracts; use Overtrue\Socialite\Exceptions\InvalidArgumentException; use Overtrue\Socialite\User; +use Overtrue\Socialite\Exceptions; class Coding extends Base { @@ -66,10 +67,11 @@ protected function getTokenFields(string $code): array /** * @throws \GuzzleHttp\Exception\GuzzleException + * @throws \Overtrue\Socialite\Exceptions\BadRequestException */ protected function getUserByToken(string $token): array { - $response = $this->getHttpClient()->get( + $responseInstance = $this->getHttpClient()->get( "$this->teamUrl/api/me", [ 'query' => [ @@ -78,7 +80,13 @@ protected function getUserByToken(string $token): array ] ); - return $this->fromJsonBody($response); + $response = $this->fromJsonBody($responseInstance); + + if (empty($response[Contracts\ABNF_ID])) { + throw new Exceptions\BadRequestException((string) $responseInstance->getBody()); + } + + return $response; } #[Pure]