From dbb9aae82a48bad5227c33543a8ea72828a06f9b Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 24 Dec 2021 22:04:48 +0100 Subject: [PATCH] [core] Do not retry POST requests automatically Signed-off-by: Knut Ahlers --- twitch/twitch.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/twitch/twitch.go b/twitch/twitch.go index 6347f18..e7f9334 100644 --- a/twitch/twitch.go +++ b/twitch/twitch.go @@ -16,6 +16,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/Luzifer/go_helpers/v2/backoff" + "github.com/Luzifer/go_helpers/v2/str" ) const ( @@ -602,7 +603,14 @@ func (c *Client) request(opts clientRequestOpts) error { "url": opts.URL, }).Trace("Execute Twitch API request") - return backoff.NewBackoff().WithMaxIterations(twitchRequestRetries).Retry(func() error { + var retries uint64 = twitchRequestRetries + if str.StringInSlice(opts.Method, []string{ + http.MethodPost, // Creates stuff, must not be retried without being asked + }) { + retries = 1 + } + + return backoff.NewBackoff().WithMaxIterations(retries).Retry(func() error { reqCtx, cancel := context.WithTimeout(opts.Context, twitchRequestTimeout) defer cancel()