Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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