| @@ 220-252 (lines=33) @@ | ||
| 217 | * @throws UnauthorizedException |
|
| 218 | * @throws PartnerRequestException |
|
| 219 | */ |
|
| 220 | protected function sendRequest($method, $uri, array $options = []) |
|
| 221 | { |
|
| 222 | try { |
|
| 223 | $response = $this->getClient()->request($method, $uri, $options); |
|
| 224 | } catch (ClientException $ex) { |
|
| 225 | $result = $ex->getResponse(); |
|
| 226 | $code = $result->getStatusCode(); |
|
| 227 | $message = $result->getReasonPhrase(); |
|
| 228 | ||
| 229 | $body = $result->getBody(); |
|
| 230 | if ($body) { |
|
| 231 | $jsonBody = json_decode($body); |
|
| 232 | if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) { |
|
| 233 | $message = $jsonBody->error->message; |
|
| 234 | } |
|
| 235 | } |
|
| 236 | ||
| 237 | if ($code === 403) { |
|
| 238 | throw new ForbiddenException($message); |
|
| 239 | } |
|
| 240 | ||
| 241 | if ($code === 401) { |
|
| 242 | throw new UnauthorizedException($message); |
|
| 243 | } |
|
| 244 | ||
| 245 | throw new PartnerRequestException( |
|
| 246 | 'Service responded with error code: "' . $code . '" and message: "' . $message . '"', |
|
| 247 | $code |
|
| 248 | ); |
|
| 249 | } |
|
| 250 | ||
| 251 | return $response; |
|
| 252 | } |
|
| 253 | ||
| 254 | /** |
|
| 255 | * Get OAuth data for header request |
|
| @@ 116-150 (lines=35) @@ | ||
| 113 | * @throws UnauthorizedException |
|
| 114 | * @throws ContentRequestException |
|
| 115 | */ |
|
| 116 | protected function sendRequest($method, $uri, array $options = []) |
|
| 117 | { |
|
| 118 | try { |
|
| 119 | $response = $this->getClient()->request($method, $uri, $options); |
|
| 120 | } catch (ClientException $ex) { |
|
| 121 | $result = $ex->getResponse(); |
|
| 122 | $code = $result->getStatusCode(); |
|
| 123 | $message = $result->getReasonPhrase(); |
|
| 124 | ||
| 125 | $body = $result->getBody(); |
|
| 126 | if ($body) { |
|
| 127 | $jsonBody = json_decode($body); |
|
| 128 | if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) { |
|
| 129 | $message = $jsonBody->error->message; |
|
| 130 | } |
|
| 131 | } |
|
| 132 | ||
| 133 | if ($code === 403) { |
|
| 134 | throw new ForbiddenException($message); |
|
| 135 | } |
|
| 136 | ||
| 137 | if ($code === 401) { |
|
| 138 | throw new UnauthorizedException($message); |
|
| 139 | } |
|
| 140 | ||
| 141 | throw new ContentRequestException( |
|
| 142 | 'Service responded with error code: "' . $code . '" and message: "' . $message . '"', |
|
| 143 | $code |
|
| 144 | ); |
|
| 145 | } |
|
| 146 | // @note: Finally? php >= 5.5 |
|
| 147 | $this->setLimits($response->getHeaders()); |
|
| 148 | ||
| 149 | return $response; |
|
| 150 | } |
|
| 151 | ||
| 152 | private function setLimits($headers) |
|
| 153 | { |
|