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

Unable to debug Validation Errors because of Guzzle truncation #56

Closed
RayHughes opened this issue Jul 7, 2022 · 1 comment
Closed

Comments

@RayHughes
Copy link

RayHughes commented Jul 7, 2022

Guzzle is truncating validation errors making it extremely difficult to debug. This seems to be an issue when Guzzle is configured to throw exceptions on errors. I have traced the problem down to Requester.php and was able to output the message by printing the message body contents.

$response = $exception->getResponse();

Example of Truncated Error

{
  "sys": {
    "type": "Error",
    "id": "InvalidEntry"
  },
  "message": "Validation error",
  "details": {
    "errors": {
      "err truncated ... )"
    }
  }
}
@Sebb767
Copy link
Collaborator

Sebb767 commented Jul 16, 2022

Hi @RayHughes ,

this is indeed annoying, but it's a problem with GuzzleHttp. You can avoid it by supplying an instance which is configured not to do so. Here's an example with the Contentful library based on this comment:

// First, create the Guzzle HTTP client
$stack = new \GuzzleHttp\HandlerStack(\GuzzleHttp\Utils::chooseHandler());
$stack->push(\GuzzleHttp\Middleware::httpErrors(new \GuzzleHttp\BodySummarizer(PHP_INT_MAX)), 'http_errors');
$stack->push(\GuzzleHttp\Middleware::redirect(), 'allow_redirects');
$stack->push(\GuzzleHttp\Middleware::cookies(), 'cookies');
$stack->push(\GuzzleHttp\Middleware::prepareBody(), 'prepare_body');
$httpClient = new \GuzzleHttp\Client(['handler' => $stack ]);

// Next, create Contentful client options and set the HTTP client
$options = \Contentful\Delivery\ClientOptions::create()->withHttpClient($httpClient);

// Finally create the client with the options
$client = new \Contentful\Delivery\Client( 'b4c0n73n7fu1', 'cfexampleapi', 'master', $options);

Hope this helps!

@Sebb767 Sebb767 closed this as completed Dec 5, 2022
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

No branches or pull requests

2 participants