PluginProbe
Media Cloud Sync / 1.2.12
Media Cloud Sync v1.2.12
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 / Api / ErrorParser / RestJsonErrorParser.php

RestJsonErrorParser.php in Media Cloud Sync 1.2.12, at includes/sdk/s3/Aws/Api/ErrorParser/RestJsonErrorParser.php

44 lines 1.6 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\Api\ErrorParser;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Parser\JsonParser;
6 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
7 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
8 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
9 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
10 /**
11 * Parses JSON-REST errors.
12 */
13 class RestJsonErrorParser extends AbstractErrorParser
14 {
15 use JsonParserTrait;
16 private $parser;
17 public function __construct(Service $api = null, JsonParser $parser = null)
18 {
19 parent::__construct($api);
20 $this->parser = $parser ?: new JsonParser();
21 }
22 public function __invoke(ResponseInterface $response, CommandInterface $command = null)
23 {
24 $data = $this->genericHandler($response);
25 // Merge in error data from the JSON body
26 if ($json = $data['parsed']) {
27 $data = \array_replace($data, $json);
28 }
29 // Correct error type from services like Amazon Glacier
30 if (!empty($data['type'])) {
31 $data['type'] = \strtolower($data['type']);
32 }
33 // Retrieve the error code from services like Amazon Elastic Transcoder
34 if ($code = $response->getHeaderLine('x-amzn-errortype')) {
35 $colon = \strpos($code, ':');
36 $data['code'] = $colon ? \substr($code, 0, $colon) : $code;
37 }
38 // Retrieve error message directly
39 $data['message'] = isset($data['parsed']['message']) ? $data['parsed']['message'] : (isset($data['parsed']['Message']) ? $data['parsed']['Message'] : null);
40 $this->populateShape($data, $response, $command);
41 return $data;
42 }
43 }
44