mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[core] Fix: Do not retry requests with status 429
which for example can happen when doing two shoutouts within the 120s cooldown period enforced by Twitch Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
3bff986ac4
commit
a1fa9972a8
3 changed files with 14 additions and 2 deletions
2
go.mod
2
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue