Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/ErrorParser/JsonRpcErrorParser.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\CommandInterface;
8 use Psr\Http\Message\ResponseInterface;
9
10 /**
11 * Parsers JSON-RPC errors.
12 */
13 class JsonRpcErrorParser extends AbstractErrorParser
14 {
15 use JsonParserTrait;
16
17 private $parser;
18
19 public function __construct(?Service $api = null, ?JsonParser $parser = null)
20 {
21 parent::__construct($api);
22 $this->parser = $parser ?: new JsonParser();
23 }
24
25 public function __invoke(
26 ResponseInterface $response,
27 ?CommandInterface $command = null
28 ) {
29 $response = AbstractParser::getResponseWithCachingStream($response);
30 $data = $this->genericHandler($response);
31
32 // Make the casing consistent across services.
33 if ($data['parsed']) {
34 $data['parsed'] = array_change_key_case($data['parsed']);
35 }
36
37 if (isset($data['parsed']['__type'])) {
38 if (!isset($data['code'])) {
39 $parts = explode('#', $data['parsed']['__type']);
40 $data['code'] = isset($parts[1]) ? $parts[1] : $parts[0];
41 }
42 $data['message'] = $data['parsed']['message'] ?? null;
43 }
44
45 $this->populateShape($data, $response, $command);
46
47 return $data;
48 }
49 }