Skip to content

Commit

Permalink
fix(joke): added retry searching joke if current server returned error
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed Apr 7, 2024
1 parent d43d6f9 commit 64936bf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkgs/command/joke.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,22 @@ 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"}
}

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{
Expand Down

0 comments on commit 64936bf

Please sign in to comment.