Skip to content

Commit 01feee5

Browse files
committed
Don't panic if YouTube quota is exceeded
1 parent 829c7b9 commit 01feee5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/streamcontrol/youtube/youtube_client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package youtube
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
8+
"net/http"
79

810
"github.com/facebookincubator/go-belt/tool/logger"
911
"google.golang.org/api/googleapi"
@@ -116,7 +118,17 @@ func (c *YouTubeClientV3) Ping(
116118
) (_err error) {
117119
logger.Tracef(ctx, "Ping")
118120
defer func() { logger.Tracef(ctx, "/Ping: %v", _err) }()
119-
return wrapRequestS(ctx, c.RequestWrapper, c.I18nLanguages.List(nil).Context(ctx).Do)
121+
err := wrapRequestS(ctx, c.RequestWrapper, c.I18nLanguages.List(nil).Context(ctx).Do)
122+
gErr := &googleapi.Error{}
123+
if err != nil && errors.As(err, &gErr) {
124+
if gErr.Code == http.StatusForbidden && len(gErr.Errors) == 1 {
125+
gErrItem := gErr.Errors[0]
126+
if gErrItem.Reason == "quotaExceeded" { // this is not an authentication or/and connection problem.
127+
return nil
128+
}
129+
}
130+
}
131+
return err
120132
}
121133

122134
func (c *YouTubeClientV3) GetBroadcasts(

0 commit comments

Comments
 (0)