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
← All changes | includes/sdk/s3/Aws/Api/ErrorParser/AbstractErrorParser.php +7 -3 1.2.01.4.1 View file →
@@ -18,9 +18,9 @@
18 18 protected $api;
19 19 /**
20 20 * @param Service $api
21 21 */
22 - public function __construct(Service $api = null)
22 + public function __construct(?Service $api = null)
23 23 {
24 24 $this->api = $api;
25 25 }
26 26 protected abstract function payload(ResponseInterface $response, StructureShape $member);
@@ -33,9 +33,9 @@
33 33 // Streaming data is just the stream from the response body.
34 34 return $response->getBody();
35 35 }
36 36 }
37 - protected function populateShape(array &$data, ResponseInterface $response, CommandInterface $command = null)
37 + protected function populateShape(array &$data, ResponseInterface $response, ?CommandInterface $command = null)
38 38 {
39 39 $data['body'] = [];
40 40 if (!empty($command) && !empty($this->api)) {
41 41 // If modeled error code is indicated, check for known error shape
@@ -42,9 +42,9 @@
42 42 if (!empty($data['code'])) {
43 43 $errors = $this->api->getOperation($command->getName())->getErrors();
44 44 foreach ($errors as $key => $error) {
45 45 // If error code matches a known error shape, populate the body
46 - if ($data['code'] == $error['name'] && $error instanceof StructureShape) {
46 + if ($this->errorCodeMatches($data, $error)) {
47 47 $modeledError = $error;
48 48 $data['body'] = $this->extractPayload($modeledError, $response);
49 49 $data['error_shape'] = $modeledError;
50 50 foreach ($error->getMembers() as $name => $member) {
@@ -65,6 +65,10 @@
65 65 }
66 66 }
67 67 }
68 68 return $data;
69 + }
70 + private function errorCodeMatches(array $data, $error) : bool
71 + {
72 + return $data['code'] == $error['name'] || isset($error['error']['code']) && $data['code'] === $error['error']['code'];
69 73 }
70 74 }