diff --git a/go.mod b/go.mod index 57d2c11..5a90520 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/Luzifer/go-openssl/v4 v4.2.1 - github.com/Luzifer/go_helpers/v2 v2.20.1 + github.com/Luzifer/go_helpers/v2 v2.22.0 github.com/Luzifer/korvike/functions v0.11.0 github.com/Luzifer/rconfig/v2 v2.4.0 github.com/Masterminds/sprig/v3 v3.2.3 diff --git a/go.sum b/go.sum index b4dbed4..cedcfcc 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/Luzifer/go-openssl/v4 v4.2.1 h1:0+/gaQ5TcBhGmVqGrfyA21eujlbbaNwj0VlOA github.com/Luzifer/go-openssl/v4 v4.2.1/go.mod h1:CZZZWY0buCtkxrkqDPQYigC4Kn55UuO97TEoV+hwz2s= github.com/Luzifer/go_helpers/v2 v2.20.1 h1:VAp2J8g31X30Xr8/eVV1Xx993MO0tQx9YwNwab6ouB4= github.com/Luzifer/go_helpers/v2 v2.20.1/go.mod h1:cIIqMPu3NT8/6kHke+03hVznNDLLKVGA74Lz47CWJyA= +github.com/Luzifer/go_helpers/v2 v2.22.0 h1:rJrZkJDzAiq4J0RUbwPI7kQ5rUy7BYQ/GUpo3fSM0y0= +github.com/Luzifer/go_helpers/v2 v2.22.0/go.mod h1:cIIqMPu3NT8/6kHke+03hVznNDLLKVGA74Lz47CWJyA= github.com/Luzifer/korvike/functions v0.11.0 h1:2hr3nnt9hy8Esu1W3h50+RggcLRXvrw92kVQLvxzd2Q= github.com/Luzifer/korvike/functions v0.11.0/go.mod h1:osumwH64mWgbwZIfE7rE0BB7Y5HXxrzyO4JfO7fhduU= github.com/Luzifer/rconfig/v2 v2.4.0 h1:MAdymTlExAZ8mx5VG8xOFAtFQSpWBipKYQHPOmYTn9o= diff --git a/pkg/twitch/twitch.go b/pkg/twitch/twitch.go index 53c22f7..31da2fe 100644 --- a/pkg/twitch/twitch.go +++ b/pkg/twitch/twitch.go @@ -90,12 +90,22 @@ type ( // ValidateStatus is the default validation function used when no // ValidateFunc is given in the ClientRequestOpts and checks for the -// returned HTTP status is equal to the OKStatus +// returned HTTP status is equal to the OKStatus. +// +// When the status is http.StatusTooManyRequests the function will +// return an error terminating any retries as retrying would not make +// sense (the error returned from Request will still be an HTTPError +// with status 429). // // When wrapping this function the body should not have been read // before in order to have the response body available in the returned // HTTPError func ValidateStatus(opts ClientRequestOpts, resp *http.Response) error { + if resp.StatusCode == http.StatusTooManyRequests { + // Twitch doesn't want to hear any more of this + return backoff.NewErrCannotRetry(newHTTPError(resp.StatusCode, nil, nil)) + } + if opts.OKStatus != 0 && resp.StatusCode != opts.OKStatus { body, err := io.ReadAll(resp.Body) if err != nil {