PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / S3 / AmbiguousSuccessParser.php

AmbiguousSuccessParser.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/S3/AmbiguousSuccessParser.php

51 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\S3;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Parser\AbstractParser;
6 use Dudlewebs\WPMCS\s3\Aws\Api\Parser\Exception\ParserException;
7 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
8 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
9 use Dudlewebs\WPMCS\s3\Aws\Exception\AwsException;
10 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
11 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
12 /**
13 * Converts errors returned with a status code of 200 to a retryable error type.
14 *
15 * @internal
16 */
17 class AmbiguousSuccessParser extends AbstractParser
18 {
19 private static $ambiguousSuccesses = ['UploadPart' => \true, 'UploadPartCopy' => \true, 'CopyObject' => \true, 'CompleteMultipartUpload' => \true];
20 /** @var callable */
21 private $errorParser;
22 /** @var string */
23 private $exceptionClass;
24 public function __construct(callable $parser, callable $errorParser, $exceptionClass = AwsException::class)
25 {
26 $this->parser = $parser;
27 $this->errorParser = $errorParser;
28 $this->exceptionClass = $exceptionClass;
29 }
30 public function __invoke(CommandInterface $command, ResponseInterface $response)
31 {
32 if (200 === $response->getStatusCode() && isset(self::$ambiguousSuccesses[$command->getName()])) {
33 $errorParser = $this->errorParser;
34 try {
35 $parsed = $errorParser($response);
36 } catch (ParserException $e) {
37 $parsed = ['code' => 'ConnectionError', 'message' => "An error connecting to the service occurred" . " while performing the " . $command->getName() . " operation."];
38 }
39 if (isset($parsed['code']) && isset($parsed['message'])) {
40 throw new $this->exceptionClass($parsed['message'], $command, ['connection_error' => \true]);
41 }
42 }
43 $fn = $this->parser;
44 return $fn($command, $response);
45 }
46 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
47 {
48 return $this->parser->parseMemberFromStream($stream, $member, $response);
49 }
50 }
51