Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/RetryableMalformedResponseParser.php

raw symbols SCIP
1 <?php
2 namespace Aws\S3;
3
4 use Aws\Api\Parser\AbstractParser;
5 use Aws\Api\StructureShape;
6 use Aws\Api\Parser\Exception\ParserException;
7 use Aws\CommandInterface;
8 use Aws\Exception\AwsException;
9 use Psr\Http\Message\ResponseInterface;
10 use Psr\Http\Message\StreamInterface;
11
12 /**
13 * Converts malformed responses to a retryable error type.
14 *
15 * @internal
16 */
17 class RetryableMalformedResponseParser extends AbstractParser
18 {
19 /** @var string */
20 private $exceptionClass;
21
22 public function __construct(
23 callable $parser,
24 $exceptionClass = AwsException::class
25 ) {
26 $this->parser = $parser;
27 $this->exceptionClass = $exceptionClass;
28 }
29
30 public function __invoke(
31 CommandInterface $command,
32 ResponseInterface $response
33 ) {
34 $fn = $this->parser;
35
36 try {
37 return $fn($command, $response);
38 } catch (ParserException $e) {
39 throw new $this->exceptionClass(
40 "Error parsing response for {$command->getName()}:"
41 . " AWS parsing error: {$e->getMessage()}",
42 $command,
43 ['connection_error' => true, 'exception' => $e],
44 $e
45 );
46 }
47 }
48
49 public function parseMemberFromStream(
50 StreamInterface $stream,
51 StructureShape $member,
52 $response
53 ) {
54 return $this->parser->parseMemberFromStream($stream, $member, $response);
55 }
56 }