1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 05:38:57 +01:00

Add TimeoutError

This commit is contained in:
Daniil Gentili 2024-06-26 17:52:50 +02:00
parent 1023a635f1
commit 56952251ee
7 changed files with 86 additions and 11 deletions

2
docs

@ -1 +1 @@
Subproject commit 5741538c101d6bad5393055f38cdfec9831d2c9c
Subproject commit 7346b4a4d3e72c4a055cb5240ffd2621cb4c00db

View File

@ -28,6 +28,10 @@ use danog\MadelineProto\Loop\InternalLoop;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\PeerNotInDbException;
use danog\MadelineProto\PTSException;
use danog\MadelineProto\RPCError\ChannelInvalidError;
use danog\MadelineProto\RPCError\ChannelPrivateError;
use danog\MadelineProto\RPCError\ChatForbiddenError;
use danog\MadelineProto\RPCError\UserBannedInChannelError;
use danog\MadelineProto\RPCErrorException;
use Revolt\EventLoop;
@ -95,18 +99,17 @@ final class UpdateLoop extends Loop
$request_pts = $state->pts();
try {
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => $this->channelId, 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true, 'floodWaitLimit' => 86400]);
} catch (ChannelPrivateError|ChatForbiddenError|ChannelInvalidError|UserBannedInChannelError) {
$this->feeder->stop();
unset($this->API->updaters[$this->channelId], $this->API->feeders[$this->channelId]);
$this->API->getChannelStates()->remove($this->channelId);
$this->API->logger("Channel private, exiting {$this}");
return self::STOP;
} catch (RPCErrorException $e) {
if ($e->rpc === '-503') {
delay(1.0);
continue;
}
if (\in_array($e->rpc, ['CHANNEL_PRIVATE', 'CHAT_FORBIDDEN', 'CHANNEL_INVALID', 'USER_BANNED_IN_CHANNEL'], true)) {
$this->feeder->stop();
unset($this->API->updaters[$this->channelId], $this->API->feeders[$this->channelId]);
$this->API->getChannelStates()->remove($this->channelId);
$this->API->logger("Channel private, exiting {$this}");
return self::STOP;
}
throw $e;
} catch (PeerNotInDbException) {
$this->feeder->stop();

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* ChannelInvalidError error.
*
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2024 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\RPCError;
use danog\MadelineProto\RPCErrorException;
/**
* The provided channel is invalid.
*
* Note: this exception is part of the raw API, and thus is not covered by the backwards-compatibility promise.
*
* Always check the changelog when upgrading, and use tools like Psalm to easily upgrade your code.
*/
final class ChannelInvalidError extends RPCErrorException
{
protected function __construct(int $code, string $caller, ?\Exception $previous = null)
{
parent::__construct('CHANNEL_INVALID', 'The provided channel is invalid.', $code, $caller, $previous);
}
}

View File

@ -0,0 +1,32 @@
<?php declare(strict_types=1);
/**
* RPCErrorException module.
*
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\RPCError;
use Amp\Cancellation;
use danog\MadelineProto\RPCErrorException;
use Exception;
use function Amp\delay;
/**
* Represents a request timeout RPC error returned by telegram.
*/
final class TimeoutError extends RPCErrorException
{
}

View File

@ -132,6 +132,7 @@ class RPCErrorException extends \Exception
'Internal_Server_Error' => true,
'INVITE_HASH_UNSYNC' => true,
'CHANNEL_ID_GENERATE_FAILED' => true,
'Invalid msgs_state_req query' => true,
];
/** @internal */
@ -284,7 +285,7 @@ class RPCErrorException extends \Exception
'CDN_METHOD_INVALID' => new self($rpc, 'You can\'t call this method in a CDN DC.', $code, $caller, $previous),
'CHANNEL_FORUM_MISSING' => new self($rpc, 'This supergroup is not a forum.', $code, $caller, $previous),
'CHANNEL_ID_INVALID' => new self($rpc, 'The specified supergroup ID is invalid.', $code, $caller, $previous),
'CHANNEL_INVALID' => new self($rpc, 'The provided channel is invalid.', $code, $caller, $previous),
'CHANNEL_INVALID' => new \danog\MadelineProto\RPCError\ChannelInvalidError($code, $caller, $previous),
'CHANNEL_PARICIPANT_MISSING' => new self($rpc, 'The current user is not in the channel.', $code, $caller, $previous),
'CHANNEL_PRIVATE' => new \danog\MadelineProto\RPCError\ChannelPrivateError($code, $caller, $previous),
'CHANNEL_TOO_BIG' => new self($rpc, 'This channel has too many participants (>1000) to be deleted.', $code, $caller, $previous),
@ -460,6 +461,7 @@ class RPCErrorException extends \Exception
'MESSAGE_NOT_MODIFIED' => new self($rpc, 'The provided message data is identical to the previous message data, the message wasn\'t modified.', $code, $caller, $previous),
'MESSAGE_POLL_CLOSED' => new self($rpc, 'Poll closed.', $code, $caller, $previous),
'MESSAGE_TOO_LONG' => new self($rpc, 'The provided message is too long.', $code, $caller, $previous),
'MESSAGE_TOO_OLD' => new self($rpc, 'The message is too old, the requested information is not available.', $code, $caller, $previous),
'METHOD_INVALID' => new self($rpc, 'The specified method is invalid.', $code, $caller, $previous),
'MIN_DATE_INVALID' => new self($rpc, 'The specified minimum date is invalid.', $code, $caller, $previous),
'MSG_ID_INVALID' => new \danog\MadelineProto\RPCError\MsgIdInvalidError($code, $caller, $previous),
@ -758,6 +760,7 @@ class RPCErrorException extends \Exception
'USER_DELETED' => new self($rpc, 'You can\'t send this secret message because the other participant deleted their account.', $code, $caller, $previous),
'USER_PRIVACY_RESTRICTED' => new self($rpc, 'The user\'s privacy settings do not allow you to do this.', $code, $caller, $previous),
'USER_RESTRICTED' => new self($rpc, 'You\'re spamreported, you can\'t create channels or chats.', $code, $caller, $previous),
'YOUR_PRIVACY_RESTRICTED' => new self($rpc, 'You cannot fetch the read date of this message because you have disallowed other users to do so for *your* messages; to fix, allow other users to see *your* exact last online date OR purchase a [Telegram Premium](https://core.telegram.org/api/premium) subscription.', $code, $caller, $previous),
'CHAT_FORBIDDEN' => new \danog\MadelineProto\RPCError\ChatForbiddenError($code, $caller, $previous),
'CALL_PROTOCOL_COMPAT_LAYER_INVALID' => new self($rpc, 'The other side of the call does not support any of the VoIP protocols supported by the local client, as specified by the `protocol.layer` and `protocol.library_versions` fields.', $code, $caller, $previous),
'FILEREF_UPGRADE_NEEDED' => new self($rpc, 'The client has to be updated in order to support [file references](https://core.telegram.org/api/file_reference).', $code, $caller, $previous),

File diff suppressed because one or more lines are too long

View File

@ -59,6 +59,7 @@ copy('https://rpc.madelineproto.xyz/v3.json', 'src/v3.json');
`rm -r src/RPCError/*`;
`git checkout src/RPCError/FloodWaitError.php`;
`git checkout src/RPCError/TimeoutError.php`;
`git checkout src/RPCError/FloodPremiumWaitError.php`;
`git checkout src/RPCError/RateLimitError.php`;
@ -81,7 +82,7 @@ $whitelist = [
FileTokenInvalidError::class => true,
\danog\MadelineProto\RPCError\RequestTokenInvalidError::class => true,
\danog\MadelineProto\RPCError\SessionPasswordNeededError::class => true,
\danog\MadelineProto\RPCError\ChannelPrivateError::class => true,
\danog\MadelineProto\RPCError\ChannelInvalidError::class => true,
\danog\MadelineProto\RPCError\ChatForbiddenError::class => true,
];
@ -98,6 +99,7 @@ foreach ($errors['result'] as $code => $sub) {
}
$code = var_export($code, true);
foreach ($sub as $err => $methods) {
$err = (string) $err;
$camel = ucfirst(StrTools::toCamelCase(strtolower($err))).'Error';
if (!preg_match('/^\w+$/', $camel)) {
continue;