Skip to content

Commit 905c7c5

Browse files
committed
Add logic to wait 15 seconds and then retry one time when Telegram API calls fail
1 parent b411ee0 commit 905c7c5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.IOException;
4040
import java.nio.file.Files;
4141
import java.nio.file.Path;
42+
import java.time.Duration;
4243
import java.util.List;
4344
import java.util.Set;
4445
import java.util.concurrent.Executor;
@@ -230,9 +231,25 @@ private <T extends BaseRequest<T, R>, R extends BaseResponse> R execute(BaseRequ
230231
return response;
231232
}
232233

234+
waitFor(Duration.ofSeconds(15));
235+
236+
response = bot.execute(request);
237+
238+
if (response.isOk()) {
239+
return response;
240+
}
241+
233242
throw new TelegramApiException(request.getMethod(), response.description());
234243
}
235244

245+
private static void waitFor(Duration duration) {
246+
try {
247+
Thread.sleep(duration);
248+
} catch (InterruptedException e) {
249+
throw new RuntimeException(e);
250+
}
251+
}
252+
236253
private static void deleteTempFiles(Set<Path> pathsToDelete) {
237254
for (var path : pathsToDelete) {
238255
try {

0 commit comments

Comments
 (0)