| @@ 284-312 (lines=29) @@ | ||
| 281 | * @throws Exception\YandexException |
|
| 282 | * @return Response |
|
| 283 | */ |
|
| 284 | protected function sendRequest($method, $uri, array $options = []) |
|
| 285 | { |
|
| 286 | try { |
|
| 287 | $response = $this->getClient()->request($method, $uri, $options); |
|
| 288 | } catch (ClientException $ex) { |
|
| 289 | // get error from response |
|
| 290 | $decodedResponseBody = $this->getDecodedBody($ex->getResponse()->getBody()); |
|
| 291 | $code = $ex->getResponse()->getStatusCode(); |
|
| 292 | ||
| 293 | // handle a service error message |
|
| 294 | if (is_array($decodedResponseBody) |
|
| 295 | && isset($decodedResponseBody['error'], $decodedResponseBody['message']) |
|
| 296 | ) { |
|
| 297 | switch ($decodedResponseBody['error']) { |
|
| 298 | case 'MissedRequiredArguments': |
|
| 299 | throw new MissedArgumentException($decodedResponseBody['message']); |
|
| 300 | case 'AssistantProfileNotFound': |
|
| 301 | throw new ProfileNotFoundException($decodedResponseBody['message']); |
|
| 302 | default: |
|
| 303 | throw new YandexException($decodedResponseBody['message'], $code); |
|
| 304 | } |
|
| 305 | } |
|
| 306 | ||
| 307 | // unknown error |
|
| 308 | throw $ex; |
|
| 309 | } |
|
| 310 | ||
| 311 | return $response; |
|
| 312 | } |
|
| 313 | ||
| 314 | /** |
|
| 315 | * @param $body |
|
| @@ 109-138 (lines=30) @@ | ||
| 106 | * @throws ProfileNotFoundException |
|
| 107 | * @throws YandexException |
|
| 108 | */ |
|
| 109 | protected function sendRequest($method, $uri, array $options = []) |
|
| 110 | { |
|
| 111 | //todo: implement Webmaster Exceptions |
|
| 112 | try { |
|
| 113 | $response = $this->getClient()->request($method, $uri, $options); |
|
| 114 | } catch (ClientException $ex) { |
|
| 115 | // get error from response |
|
| 116 | $decodedResponseBody = $this->getDecodedBody($ex->getResponse()->getBody()); |
|
| 117 | $code = $ex->getResponse()->getStatusCode(); |
|
| 118 | ||
| 119 | // handle a service error message |
|
| 120 | if (is_array($decodedResponseBody) |
|
| 121 | && isset($decodedResponseBody['error'], $decodedResponseBody['message']) |
|
| 122 | ) { |
|
| 123 | switch ($decodedResponseBody['error']) { |
|
| 124 | case 'MissedRequiredArguments': |
|
| 125 | throw new MissedArgumentException($decodedResponseBody['message']); |
|
| 126 | case 'AssistantProfileNotFound': |
|
| 127 | throw new ProfileNotFoundException($decodedResponseBody['message']); |
|
| 128 | default: |
|
| 129 | throw new YandexException($decodedResponseBody['message'], $code); |
|
| 130 | } |
|
| 131 | } |
|
| 132 | ||
| 133 | // unknown error |
|
| 134 | throw $ex; |
|
| 135 | } |
|
| 136 | ||
| 137 | return $response; |
|
| 138 | } |
|
| 139 | ||
| 140 | /** |
|
| 141 | * @param string $resource |
|