|
11 | 11 | namespace Longman\TelegramBot; |
12 | 12 |
|
13 | 13 | use GuzzleHttp\Client; |
14 | | -use GuzzleHttp\Exception\RequestException; |
15 | 14 | use Longman\TelegramBot\Entities\File; |
16 | 15 | use Longman\TelegramBot\Entities\ServerResponse; |
17 | 16 | use Longman\TelegramBot\Exception\TelegramException; |
18 | | -use Longman\TelegramBot\Exception\TelegramSlowModeException; |
| 17 | +use Longman\TelegramBot\Exception\Request\RequestException; |
| 18 | +use Longman\TelegramBot\Exception\Request\TooManyRequests; |
19 | 19 |
|
20 | 20 | class Request |
21 | 21 | { |
@@ -208,16 +208,15 @@ public static function execute($action, array $data = null) |
208 | 208 | '/bot' . self::$telegram->getApiKey() . '/' . $action, |
209 | 209 | $request_params |
210 | 210 | ); |
211 | | - } catch (RequestException $e) { |
212 | | - //throw new TelegramException($e->getMessage()); |
| 211 | + } catch (\GuzzleHttp\Exception\RequestException $e) { |
213 | 212 | $error_code = $e->getResponse()->getStatusCode(); |
214 | 213 | if ($error_code == 429) { |
215 | 214 | //echo Psr7\Message::toString($e->getRequest()); |
216 | 215 | //echo Psr7\Message::toString($e->getResponse()); |
217 | 216 | //print($e); |
218 | | - throw new TelegramSlowModeException($e->getResponse()->getBody()->getContents(), $error_code); |
| 217 | + throw new TooManyRequests($e->getResponse()->getBody()->getContents(), $error_code); |
219 | 218 | } |
220 | | - throw new TelegramException($e->getResponse()->getBody()->getContents(), $error_code); |
| 219 | + throw new RequestException($e->getResponse()->getBody()->getContents(), $error_code); |
221 | 220 | } finally { |
222 | 221 | //Logging verbose debug output |
223 | 222 | TelegramLog::endDebugLogTempStream("Verbose HTTP Request output:\n%s\n"); |
@@ -259,14 +258,13 @@ public static function downloadFile(File $file) |
259 | 258 | '/file/bot' . self::$telegram->getApiKey() . '/' . $path, |
260 | 259 | ['debug' => $debug_handle, 'sink' => $loc_path] |
261 | 260 | ); |
262 | | - } catch (RequestException $e) { |
263 | | - //throw new TelegramException($e->getMessage()); |
264 | | - throw new TelegramException($e->getResponse()->getBody()->getContents()); |
| 261 | + } catch (\GuzzleHttp\Exception\RequestException $e) { |
| 262 | + $error_code = $e->getResponse()->getStatusCode(); |
| 263 | + throw new RequestException($e->getResponse()->getBody()->getContents(), $error_code); |
265 | 264 | } finally { |
266 | 265 | //Logging verbose debug output |
267 | 266 | TelegramLog::endDebugLogTempStream("Verbose HTTP File Download Request output:\n%s\n"); |
268 | 267 | } |
269 | | - |
270 | 268 | return (filesize($loc_path) > 0); |
271 | 269 | } |
272 | 270 |
|
|
0 commit comments