diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs
index e925cac..7ce93c1 100644
--- a/TelegramBotBase/Sessions/DeviceSession.cs
+++ b/TelegramBotBase/Sessions/DeviceSession.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
@@ -770,20 +770,24 @@ namespace TelegramBotBase.Sessions
///
public async Task API(Func> call)
{
- try
+ var numberOfTries = 0;
+ while (numberOfTries < DeviceSession.MaxNumberOfRetries)
{
- return await call(this.Client.TelegramClient);
- }
- catch (ApiRequestException ex)
- {
- if (ex.Parameters != null)
+ try
{
- await Task.Delay(ex.Parameters.RetryAfter);
+ return await call(Client.TelegramClient);
+ }
+ catch (ApiRequestException ex)
+ {
+ if (ex.ErrorCode != 429)
+ throw;
- return await call(this.Client.TelegramClient);
+ if (ex.Parameters != null)
+ await Task.Delay(ex.Parameters.RetryAfter * 1000);
+
+ numberOfTries++;
}
}
-
return default(T);
}
@@ -794,17 +798,23 @@ namespace TelegramBotBase.Sessions
///
public async Task API(Func call)
{
- try
+ var numberOfTries = 0;
+ while (numberOfTries < DeviceSession.MaxNumberOfRetries)
{
- await call(this.Client.TelegramClient);
- }
- catch (ApiRequestException ex)
- {
- if (ex.Parameters != null)
+ try
{
- await Task.Delay(ex.Parameters.RetryAfter);
+ await call(Client.TelegramClient);
+ return;
+ }
+ catch (ApiRequestException ex)
+ {
+ if (ex.ErrorCode != 429)
+ throw;
- await call(this.Client.TelegramClient);
+ if (ex.Parameters != null)
+ await Task.Delay(ex.Parameters.RetryAfter * 1000);
+
+ numberOfTries++;
}
}
}