Skip to content

Commit fffac70

Browse files
committed
Read input data from error stream
1 parent b0b6c15 commit fffac70

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/telegram/TelegramBotApi.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ function query($method, array $args = [], bool $multipart = false){
196196
else{
197197
$connection->getOutputStream()->write($this->json->format($args));
198198
}
199+
199200
if($connection->responseCode != 200){
200-
throw new TelegramException("Server response invalid status code {$connection->responseCode}");
201+
$rawResponse = $connection->getErrorStream()->readFully();
202+
if(strlen($rawResponse) == 0) throw new TelegramException("Server response invalid status code {$connection->responseCode}");
203+
} else {
204+
$rawResponse = $connection->getInputStream()->readFully();
201205
}
202-
$rawResponse = $connection->getInputStream()->readFully();
206+
203207
$connection->disconnect();
204208
$response = $this->json->parse($rawResponse);
205209
if(!$response->ok){

0 commit comments

Comments
 (0)