Skip to content

Commit

Permalink
Reduce logs 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Apr 19, 2021
1 parent 9ffb1e6 commit 959ebf0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Controllers/AbstractApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Amp\Http\Server\Router;
use Amp\Promise;
use danog\MadelineProto\API;
use TelegramApiServer\Exceptions\NoMediaException;
use TelegramApiServer\Exceptions\NoticeException;
use TelegramApiServer\Logger;
use TelegramApiServer\MadelineProtoExtensions\ApiExtensions;
use TelegramApiServer\MadelineProtoExtensions\SystemApiExtensions;
Expand Down Expand Up @@ -142,7 +142,7 @@ private function generateResponse(): \Generator
}

} catch (\Throwable $e) {
if (!$e instanceof NoMediaException) {
if (!$e instanceof NoticeException) {
error($e->getMessage(), Logger::getExceptionAsArray($e));
} else {
notice($e->getMessage());
Expand Down
8 changes: 8 additions & 0 deletions src/Exceptions/MediaTooBig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace TelegramApiServer\Exceptions;

class MediaTooBig extends NoticeException
{

}
2 changes: 1 addition & 1 deletion src/Exceptions/NoMediaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TelegramApiServer\Exceptions;

class NoMediaException extends \Exception
class NoMediaException extends NoticeException
{

}
8 changes: 8 additions & 0 deletions src/Exceptions/NoticeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace TelegramApiServer\Exceptions;

class NoticeException extends \Exception
{

}
8 changes: 4 additions & 4 deletions src/MadelineProtoExtensions/ApiExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Amp\Promise;
use danog\MadelineProto;
use danog\MadelineProto\TL\Conversion\BotAPI;
use OutOfRangeException;
use TelegramApiServer\EventObservers\EventHandler;
use TelegramApiServer\Exceptions\MediaTooBig;
use TelegramApiServer\Exceptions\NoMediaException;
use function Amp\call;

Expand Down Expand Up @@ -375,7 +375,7 @@ function() use ($data) {
}

if ($data['size_limit'] && $info['size'] > $data['size_limit']) {
throw new OutOfRangeException(
throw new MediaTooBig(
"Media exceeds size limit. Size: {$info['size']} bytes; limit: {$data['size_limit']} bytes"
);
}
Expand Down Expand Up @@ -524,13 +524,13 @@ public function downloadToBrowser(array $info): Promise
* Upload file from POST request.
* Response can be passed to 'media' field in messages.sendMedia.
*
* @throws \InvalidArgumentException
* @return Promise
* @throws NoMediaException
*/
public function uploadMediaForm(): Promise
{
if (empty($this->file)) {
throw new \InvalidArgumentException('File not found');
throw new NoMediaException('File not found');
}
return call(function() {
$inputFile = yield $this->madelineProto->uploadFromStream(
Expand Down

0 comments on commit 959ebf0

Please sign in to comment.