Skip to content

Existence of a user #787

Closed
Closed

Description

@christiancozzolino

Hi, how can I check the existence of a user?
I tried using this:

$user = $client->api('user')->show('usernameToSearch');

If the user exists, I don't find any problems; if the user does not exist, I get this:

Fatal error: Uncaught Github\Exception\RuntimeException: Not Found in C:\xampp\htdocs\github\vendor\knplabs\github-api\lib\Github\HttpClient\Plugin\GithubExceptionThrower.php:98 Stack trace: #0 C:\xampp\htdocs\github\vendor\php-http\httplug\src\Promise\HttpFulfilledPromise.php(34): Github\HttpClient\Plugin\GithubExceptionThrower->Github\HttpClient\Plugin{closure}(Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\github\vendor\knplabs\github-api\lib\Github\HttpClient\Plugin\GithubExceptionThrower.php(99): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure)) #2 C:\xampp\htdocs\github\vendor\php-http\client-common\src\PluginClient.php(161): Github\HttpClient\Plugin\GithubExceptionThrower->handleRequest(Object(GuzzleHttp\Psr7\Request), Object(Closure), Object(Closure)) #3 C:\xampp\htdocs\github\vendor\php-http\client-common\src\PluginClient.php(175): Http\Client\Common\PluginClient->Http\Client\Common{closure}(Object(GuzzleHttp\Psr7\Request)) #4 C:\xampp\htdocs\github\vendor\php-http\client-common\src\PluginCl in C:\xampp\htdocs\github\vendor\knplabs\github-api\lib\Github\HttpClient\Plugin\GithubExceptionThrower.php on line 98

My goal is to show a "User does not exist" message, rather than showing the Fatal Error.

Activity

  1. christiancozzolino commented on Apr 16, 2019

    @christiancozzolino
    Author

    I solved this:

    try
    {
    $user = $client->api('user')->show('usernameToSearch');
    }
    catch (\RuntimeException $e)
    {
    print 'User does not exist';
    }

    is it right for you?

  2. acrobat commented on Apr 17, 2019

    @acrobat
    Collaborator

    @christiancozzolino The runtime exception is a general exception, so it could also be thrown when other errors occur. But depending on the use case this might help you out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions