null, 'message' => null, 'type' => $response->isClientError() ? 'client' : 'server', 'request_id' => (string) $response->getHeader('x-amzn-RequestId'), 'parsed' => null ); // Parse the json and normalize key casings if (null !== $json = json_decode($response->getBody(true), true)) { $data['parsed'] = array_change_key_case($json); } // Do additional, protocol-specific parsing and return the result $data = $this->doParse($data, $response); // Remove "Fault" suffix from exception names if (isset($data['code']) && strpos($data['code'], 'Fault')) { $data['code'] = preg_replace('/^([a-zA-Z]+)Fault$/', '$1', $data['code']); } return $data; } /** * Pull relevant exception data out of the parsed json * * @param array $data The exception data * @param Response $response The response from the service containing the error * * @return array */ abstract protected function doParse(array $data, Response $response); }