Giter Club home page Giter Club logo

Comments (3)

yash30201 avatar yash30201 commented on August 26, 2024 1

Thanks for more info.

What's happening here is that error is being thrown from auth library as part of the GRPC Transport when it's trying to fetch the auth token. Doing so, it will always use HTTP (hence REST).

Exceptions are wrapped as ApiCore\ApiException so that they don't differ with transport (GRPC or REST). But since auth calls are always HTTP and they don't change based on transport so they are not wrapped.

It's not intuitive but it's still Working as Intended.

from gax-php.

yash30201 avatar yash30201 commented on August 26, 2024

Hi @tscni, thanks for raising this.

Can you please provide a repro case for this error so that I can try this out at my end?
Also, can you try doing this with latest versions of gax-php and auth and see if the error exists?

from gax-php.

tscni avatar tscni commented on August 26, 2024

Sure (I'm using google/cloud-retail as an example here)

  1. Use PHP 8.1 (the version shouldn't matter) + necessary common extensions (like curl)
  2. Create the following files in a new direfctory
    • composer.json
      {
         "require": {
             "google/auth": "1.28.0",
             "google/cloud-retail": "1.4.0",
             "google/gax": "1.21.1"
         }
      }
    • index.php
      <?php
      
      use Google\Cloud\Retail\V2\PredictionServiceClient;
      use Google\Cloud\Retail\V2\UserEvent;
      
      require __DIR__ . '/vendor/autoload.php';
      
      $client = new PredictionServiceClient([
          'credentials' => [
              'type' => 'authorized_user',
              'client_id' => 'invalid',
              'client_secret' => 'invalid',
              'refresh_token' => 'invalid',
          ],
      ]);
      try {
          $client->predict('placement', new UserEvent());
      } catch (Throwable $exception) {
          var_dump($exception->getMessage());
          var_dump(get_class($exception));
      }
  3. Run composer install in that directory
  4. Run php index.php
  5. Observe expected (-) vs. actual (+) output
     string(190) "Client error: `POST https://oauth2.googleapis.com/token` resulted in a `401 Unauthorized` response:
     {
       "error": "invalid_client",
       "error_description": "The OAuth client was not found."
     }
     "
    -string(27) "Google\ApiCore\ApiException"
    +string(36) "GuzzleHttp\Exception\ClientException"
  6. Remove your internet connection
  7. Run php index.php
  8. Observe expected (-) vs. actual (+) output
     string(156) "cURL error 6: Could not resolve host: oauth2.googleapis.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) 
     for https://oauth2.googleapis.com/token"
    -string(27) "Google\ApiCore\ApiException"
    +string(37) "GuzzleHttp\Exception\ConnectException"

from gax-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.