| 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 |
|
| 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 |
|
| 34 |
if ($json = $data['parsed']) { |
| 35 |
$data = array_replace($json, $data); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
if (!empty($data['type'])) { |
| 40 |
$data['type'] = strtolower($data['type']); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 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 |
} |