| 1 |
efrain |
1 |
<?php
|
|
|
2 |
namespace Aws\Api\ErrorParser;
|
|
|
3 |
|
|
|
4 |
use Aws\Api\Parser\PayloadParserTrait;
|
|
|
5 |
use Aws\Api\StructureShape;
|
|
|
6 |
use Psr\Http\Message\ResponseInterface;
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* Provides basic JSON error parsing functionality.
|
|
|
10 |
*/
|
|
|
11 |
trait JsonParserTrait
|
|
|
12 |
{
|
|
|
13 |
use PayloadParserTrait;
|
|
|
14 |
|
|
|
15 |
private function genericHandler(ResponseInterface $response)
|
|
|
16 |
{
|
|
|
17 |
$code = (string) $response->getStatusCode();
|
|
|
18 |
if ($this->api
|
|
|
19 |
&& !is_null($this->api->getMetadata('awsQueryCompatible'))
|
|
|
20 |
&& $response->getHeaderLine('x-amzn-query-error')
|
|
|
21 |
) {
|
|
|
22 |
$queryError = $response->getHeaderLine('x-amzn-query-error');
|
|
|
23 |
$parts = explode(';', $queryError);
|
|
|
24 |
if (isset($parts) && count($parts) == 2 && $parts[0] && $parts[1]) {
|
|
|
25 |
$error_code = $parts[0];
|
|
|
26 |
$error_type = $parts[1];
|
|
|
27 |
}
|
|
|
28 |
}
|
|
|
29 |
if (!isset($error_type)) {
|
|
|
30 |
$error_type = $code[0] == '4' ? 'client' : 'server';
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
return [
|
|
|
34 |
'request_id' => (string) $response->getHeaderLine('x-amzn-requestid'),
|
|
|
35 |
'code' => isset($error_code) ? $error_code : null,
|
|
|
36 |
'message' => null,
|
|
|
37 |
'type' => $error_type,
|
|
|
38 |
'parsed' => $this->parseJson($response->getBody(), $response)
|
|
|
39 |
];
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
protected function payload(
|
|
|
43 |
ResponseInterface $response,
|
|
|
44 |
StructureShape $member
|
|
|
45 |
) {
|
|
|
46 |
$jsonBody = $this->parseJson($response->getBody(), $response);
|
|
|
47 |
|
|
|
48 |
if ($jsonBody) {
|
|
|
49 |
return $this->parser->parse($member, $jsonBody);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|