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