From 64936bff2687747a85ff41c28dff82f23639537c Mon Sep 17 00:00:00 2001 From: Wittano Bonarotti Date: Sun, 7 Apr 2024 08:51:54 +0200 Subject: [PATCH] fix(joke): added retry searching joke if current server returned error --- pkgs/command/joke.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/command/joke.go b/pkgs/command/joke.go index fa5928e..81802f1 100644 --- a/pkgs/command/joke.go +++ b/pkgs/command/joke.go @@ -58,6 +58,13 @@ func (j JokeCommand) Command() *discordgo.ApplicationCommand { func (j JokeCommand) Execute(ctx context.Context, _ *discordgo.Session, i *discordgo.InteractionCreate) (DiscordMessageReceiver, error) { searchQuery := getJokeSearchParameters(ctx, i.Data.(discordgo.ApplicationCommandInteractionData)) +findJoke: + select { + case <-ctx.Done(): + return nil, context.Canceled + default: + } + service, err := selectGetService(ctx, j.Services) if err != nil { return nil, ErrorResponse{err, "Nie udało mi się, znaleść żadnego żartu"} @@ -65,7 +72,8 @@ func (j JokeCommand) Execute(ctx context.Context, _ *discordgo.Session, i *disco res, err := service.Get(ctx, searchQuery) if err != nil { - return nil, err + slog.With(requestIDKey, ctx.Value(requestIDKey)).ErrorContext(ctx, err.Error()) + goto findJoke } return jokeResponse{