Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: double default truncateAt for guzzle error output #415

Merged
merged 6 commits into from
Sep 26, 2022

Conversation

bshaffer
Copy link
Contributor

@bshaffer bshaffer commented Sep 14, 2022

Guzzle 7 Only

This will help the user receive a more helpful error message when encountering Google API exceptions. For example, with the "reAuth" error:

Before

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
  "error": "invalid_grant",
  "error_description": "reauth related error (rapt_required)",
  "error_uri": "https://sup (truncated...)
 in /path/to/project/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

After

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
  "error": "invalid_grant",
  "error_description": "reauth related error (rapt_required)",
  "error_uri": "https://support.google.com/a/answer/9368756",
  "error_subtype": "rapt_required"
}
 in /path/to/project/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

@bshaffer bshaffer requested a review from a team as a code owner September 14, 2022 20:21
Copy link

@TimurSadykov TimurSadykov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for a quick fix!

$stack = null;
if (class_exists(BodySummarizer::class)) {
// double the # of characters before truncation by default
$bodySummarizer = new BodySummarizer(240);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be made configurable somehow? Is there already a way to configure things in this package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible for the end user to pass in custom guzzle clients like this:

$http = new GuzzleHttp\Client($someCustomConfig);
$assetClient = new AssetServiceGapicClient([
    'credentialsConfig' => [
        'authHttpHandler' => $http, // for calls made to the token endpoint
    ],
    'rest' => [
        'httpHandler' => $http,     // for calls made to the API using REST
    ]
]);

However, this change is to modify the default value, so we're just hardcoding it.

@bshaffer bshaffer merged commit e2f6a89 into main Sep 26, 2022
@bshaffer bshaffer deleted the double-size-of-guzzle-truncation branch September 26, 2022 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants