@@ 83-111 (lines=29) @@ | ||
80 | * @throws UnauthorizedException |
|
81 | * @throws MetricaException |
|
82 | */ |
|
83 | protected function sendRequest($method, $uri, array $options = []) |
|
84 | { |
|
85 | try { |
|
86 | $response = $this->getClient()->request($method, $uri, $options); |
|
87 | } catch (ClientException $ex) { |
|
88 | $result = $ex->getResponse(); |
|
89 | $code = $result->getStatusCode(); |
|
90 | $message = $result->getReasonPhrase(); |
|
91 | ||
92 | if ($code === 403) { |
|
93 | throw new ForbiddenException($message); |
|
94 | } |
|
95 | ||
96 | if ($code === 401) { |
|
97 | throw new UnauthorizedException($message); |
|
98 | } |
|
99 | ||
100 | if ($code === 429) { |
|
101 | throw new TooManyRequestsException($message); |
|
102 | } |
|
103 | ||
104 | throw new MetricaException( |
|
105 | 'Service responded with error code: "' . $code . '" and message: "' . $message . '"', |
|
106 | $code |
|
107 | ); |
|
108 | } |
|
109 | ||
110 | return $response; |
|
111 | } |
|
112 | ||
113 | /** |
|
114 | * Send GET request to API resource |
@@ 155-183 (lines=29) @@ | ||
152 | * @throws SafeBrowsingException |
|
153 | * @throws NotFoundException |
|
154 | */ |
|
155 | protected function sendRequest($method, $uri, array $options = []) |
|
156 | { |
|
157 | try { |
|
158 | $response = $this->getClient()->request($method, $uri, $options); |
|
159 | } catch (ClientException $ex) { |
|
160 | $result = $ex->getResponse(); |
|
161 | $code = $result->getStatusCode(); |
|
162 | $message = $result->getReasonPhrase(); |
|
163 | ||
164 | if ($code === 403) { |
|
165 | throw new ForbiddenException($message); |
|
166 | } |
|
167 | ||
168 | if ($code === 401) { |
|
169 | throw new UnauthorizedException($message); |
|
170 | } |
|
171 | ||
172 | if ($code === 404) { |
|
173 | throw new NotFoundException($message); |
|
174 | } |
|
175 | ||
176 | throw new SafeBrowsingException( |
|
177 | 'Service responded with error code: "' . $code . '" and message: "' . $message . '"', |
|
178 | $code |
|
179 | ); |
|
180 | } |
|
181 | ||
182 | return $response; |
|
183 | } |
|
184 | ||
185 | /** |
|
186 | * @param string $bodyString |