mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Merge pull request #283 from knocte/throwInsteadOfSleep
Throw FloodException instead of calling Thread.Sleep()
This commit is contained in:
commit
8b04f82846
|
|
@ -211,8 +211,8 @@ TLSharp library should automatically handle these errors. If you see such errors
|
|||
|
||||
You should create a Telegram session. See [configuration guide](#sending-messages-set-up)
|
||||
|
||||
#### Why I get FLOOD_WAIT error?
|
||||
[It's Telegram restrictions](https://core.telegram.org/api/errors#420-flood)
|
||||
#### Why do I get a FloodException/FLOOD_WAIT error?
|
||||
It's likely [Telegram restrictions](https://core.telegram.org/api/errors#420-flood), or a bug in TLSharp (if you feel it's the latter, please open a Github issue). You can know the time to wait by accessing the FloodException::TimeToWait property.
|
||||
|
||||
#### Why does TLSharp lacks feature XXXX?
|
||||
|
||||
|
|
|
|||
|
|
@ -272,8 +272,7 @@ namespace TLSharp.Core.Network
|
|||
{
|
||||
var resultString = Regex.Match(errorMessage, @"\d+").Value;
|
||||
var seconds = int.Parse(resultString);
|
||||
Debug.WriteLine($"Should wait {seconds} sec.");
|
||||
Thread.Sleep(1000 * seconds);
|
||||
throw new FloodException(TimeSpan.FromSeconds(seconds));
|
||||
}
|
||||
else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
|
||||
{
|
||||
|
|
@ -499,6 +498,18 @@ namespace TLSharp.Core.Network
|
|||
}
|
||||
}
|
||||
|
||||
public class FloodException : Exception
|
||||
{
|
||||
public TimeSpan TimeToWait { get; private set; }
|
||||
|
||||
internal FloodException(TimeSpan timeToWait)
|
||||
: base($"Flood prevention. Telegram now requires your program to do requests again only after {timeToWait.TotalSeconds} seconds have passed ({nameof(TimeToWait)} property)." +
|
||||
" If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please.")
|
||||
{
|
||||
TimeToWait = timeToWait;
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class DataCenterMigrationException : Exception
|
||||
{
|
||||
internal int DC { get; private set; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue