summaryrefslogtreecommitdiff
path: root/vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
committerAndrew Dolgov <[email protected]>2022-11-23 21:14:33 +0300
commit0c8af4992cb0f7589dcafaad65ada12753c64594 (patch)
tree18e83d068c3e7dd2499331de977782b382279396 /vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php
initial
Diffstat (limited to 'vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php')
-rw-r--r--vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php b/vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php
new file mode 100644
index 0000000..92b447c
--- /dev/null
+++ b/vendor/aws/aws-sdk-php/src/Api/ErrorParser/JsonParserTrait.php
@@ -0,0 +1,52 @@
+<?php
+namespace Aws\Api\ErrorParser;
+
+use Aws\Api\Parser\PayloadParserTrait;
+use Aws\Api\StructureShape;
+use Psr\Http\Message\ResponseInterface;
+
+/**
+ * Provides basic JSON error parsing functionality.
+ */
+trait JsonParserTrait
+{
+ use PayloadParserTrait;
+
+ private function genericHandler(ResponseInterface $response)
+ {
+ $code = (string) $response->getStatusCode();
+ if ($this->api
+ && $this->api->getMetadata('awsQueryCompatible')
+ && $response->getHeaderLine('x-amzn-query-error')
+ ) {
+ $queryError = $response->getHeaderLine('x-amzn-query-error');
+ $parts = explode(';', $queryError);
+ if (isset($parts) && count($parts) == 2 && $parts[0] && $parts[1]) {
+ $error_code = $parts[0];
+ $error_type = $parts[1];
+ }
+ }
+ if (!isset($error_type)) {
+ $error_type = $code[0] == '4' ? 'client' : 'server';
+ }
+
+ return [
+ 'request_id' => (string) $response->getHeaderLine('x-amzn-requestid'),
+ 'code' => isset($error_code) ? $error_code : null,
+ 'message' => null,
+ 'type' => $error_type,
+ 'parsed' => $this->parseJson($response->getBody(), $response)
+ ];
+ }
+
+ protected function payload(
+ ResponseInterface $response,
+ StructureShape $member
+ ) {
+ $jsonBody = $this->parseJson($response->getBody(), $response);
+
+ if ($jsonBody) {
+ return $this->parser->parse($member, $jsonBody);
+ }
+ }
+}