Skip to content

Commit

Permalink
Fix: empty preview
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Apr 9, 2023
1 parent e4947c5 commit 3e4c91a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/TgClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Amp\Http\HttpResponse;
use Amp\Http\HttpStatus;
use UnexpectedValueException;

use function Amp\delay;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function getHistoryHtml(array $data): array
return self::getContents($this->get('getHistoryHtml', ['data' => $data]));
}

public function getMedia(array $data, array $headers): Response
public function getMedia(array $data, array $headers): HttpResponse
{
$data = array_merge(
[
Expand All @@ -63,7 +65,7 @@ public function getMedia(array $data, array $headers): Response
return $this->get('getMedia', ['data' => $data], $headers, 'media');
}

public function getMediaPreview(array $data, array $headers): Response
public function getMediaPreview(array $data, array $headers): HttpResponse
{
$data = array_merge(
[
Expand Down Expand Up @@ -128,7 +130,7 @@ private function get(
array $headers = [],
string $responseType = 'json',
int $retry = 0
): Response {
): HttpResponse {
unset(
$headers['host'],
$headers['remote_addr'],
Expand Down Expand Up @@ -175,6 +177,9 @@ private function get(
return $this->get($method, $parameters, $headers, $responseType, ++$retry);
}
if ($errorMessage) {
if ($errorMessage === 'Message has no preview' || $errorMessage === 'Empty preview') {
return new \Amp\Http\Server\Response(HttpStatus::TEMPORARY_REDIRECT, ['location' => '/no-image.jpg']);
}
throw new UnexpectedValueException($errorMessage, $errorCode);
}
throw new UnexpectedValueException(static::MESSAGE_CLIENT_UNAVAILABLE, $response->getStatus());
Expand Down

0 comments on commit 3e4c91a

Please sign in to comment.