From 734cdeef1294119100b3f650c988b8ba6caed2c0 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 25 Aug 2024 17:02:58 +0800 Subject: Retry the HTTP calls occasionally --- src/Bot.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/Bot.zig') diff --git a/src/Bot.zig b/src/Bot.zig index adfafef..8e69579 100644 --- a/src/Bot.zig +++ b/src/Bot.zig @@ -135,6 +135,26 @@ fn call( comptime method: HttpMethod, uri: Uri, data: ?[]const u8, +) !Parsed(T) { + var tries: i8 = 0; + while (true) : (tries += 1) { + if (self.wrappedCall(T, method, uri, data)) |res| { + return res; + } else |err| { + std.log.warn("error when performing call: {}", .{err}); + if (tries == 20) { + return err; + } + } + } +} + +fn wrappedCall( + self: *Bot, + comptime T: type, + comptime method: HttpMethod, + uri: Uri, + data: ?[]const u8, ) !Parsed(T) { while (true) { var request = try self.http_client.open(method, uri, .{ -- cgit v1.2.3