Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/ErrorParser/RestJsonErrorParser.php

raw symbols SCIP
1 <?php
2 namespace Aws\Api\ErrorParser;
3
4 use Aws\Api\Parser\AbstractParser;
5 use Aws\Api\Parser\JsonParser;
6 use Aws\Api\Service;
7 use Aws\Api\StructureShape;
8 use Aws\CommandInterface;
9 use Psr\Http\Message\ResponseInterface;
10
11 /**
12 * Parses JSON-REST errors.
13 */
14 class RestJsonErrorParser extends AbstractErrorParser
15 {
16 use JsonParserTrait;
17
18 private $parser;
19
20 public function __construct(?Service $api = null, ?JsonParser $parser = null)
21 {
22 parent::__construct($api);
23 $this->parser = $parser ?: new JsonParser();
24 }
25
26 public function __invoke(
27 ResponseInterface $response,
28 ?CommandInterface $command = null
29 ) {
30 $response = AbstractParser::getResponseWithCachingStream($response);
31 $data = $this->genericHandler($response);
32
33 // Merge in error data from the JSON body
34 if ($json = $data['parsed']) {
35 $data = array_replace($json, $data);
36 }
37
38 // Correct error type from services like Amazon Glacier
39 if (!empty($data['type'])) {
40 $data['type'] = strtolower($data['type']);
41 }
42
43 // Retrieve error message directly
44 $data['message'] = $data['parsed']['message']
45 ?? $data['parsed']['Message']
46 ?? $data['parsed']['error_description']
47 ?? null;
48
49 $this->populateShape($data, $response, $command);
50
51 return $data;
52 }
53 }