@@ 219-251 (lines=33) @@ | ||
216 | * @throws UnauthorizedException |
|
217 | * @throws PartnerRequestException |
|
218 | */ |
|
219 | protected function sendRequest($method, $uri, array $options = []) |
|
220 | { |
|
221 | try { |
|
222 | $response = $this->getClient()->request($method, $uri, $options); |
|
223 | } catch (ClientException $ex) { |
|
224 | $result = $ex->getResponse(); |
|
225 | $code = $result->getStatusCode(); |
|
226 | $message = $result->getReasonPhrase(); |
|
227 | ||
228 | $body = $result->getBody(); |
|
229 | if ($body) { |
|
230 | $jsonBody = json_decode($body); |
|
231 | if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) { |
|
232 | $message = $jsonBody->error->message; |
|
233 | } |
|
234 | } |
|
235 | ||
236 | if ($code === 403) { |
|
237 | throw new ForbiddenException($message); |
|
238 | } |
|
239 | ||
240 | if ($code === 401) { |
|
241 | throw new UnauthorizedException($message); |
|
242 | } |
|
243 | ||
244 | throw new PartnerRequestException( |
|
245 | 'Service responded with error code: "' . $code . '" and message: "' . $message . '"', |
|
246 | $code |
|
247 | ); |
|
248 | } |
|
249 | ||
250 | return $response; |
|
251 | } |
|
252 | ||
253 | /** |
|
254 | * 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 | { |