Skip to content

Commit eaa0ba6

Browse files
committed
:octocat: improve "/me" endpoint error detection
1 parent 2a9f087 commit eaa0ba6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Core/OAuthProvider.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
};
2727
use Psr\Log\{LoggerInterface, NullLogger};
2828
use ReflectionClass;
29-
use function array_merge, array_shift, explode, implode, in_array, is_array, is_string, ltrim,
29+
use function array_key_exists, array_merge, array_shift, explode, implode, in_array, is_array, is_string, ltrim,
3030
random_bytes, rtrim, sodium_bin2hex, sprintf, str_contains, str_starts_with, strip_tags, strtolower;
3131
use const PHP_QUERY_RFC1738;
3232

@@ -515,12 +515,21 @@ final protected function handleMeResponseError(ResponseInterface $response):void
515515
// let's try the common fields
516516
foreach(['error_description', 'message', 'error', 'meta', 'data', 'detail', 'status', 'text'] as $err){
517517

518-
if(isset($json[$err]) && is_string($json[$err])){
518+
if(!array_key_exists($err, $json)){
519+
continue;
520+
}
521+
522+
if(is_string($json[$err])){
519523
throw new ProviderException($json[$err]);
520524
}
521525
elseif(is_array($json[$err])){
522526
foreach(['message', 'error', 'errorDetail', 'developer_message', 'msg', 'code'] as $errDetail){
523-
if(isset($json[$err][$errDetail]) && is_string($json[$err][$errDetail])){
527+
528+
if(!array_key_exists($errDetail, $json[$err])){
529+
continue;
530+
}
531+
532+
if(is_string($json[$err][$errDetail])){
524533
throw new ProviderException($json[$err][$errDetail]);
525534
}
526535
}

0 commit comments

Comments
 (0)