Skip to content

Commit

Permalink
fix: unwrap *url.Error in scavengeRetrieveError
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-ignacio committed Dec 22, 2023
1 parent 7515f8a commit f626fa5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gentei/apis/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
irand "math/rand"
"net/http"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -99,11 +100,16 @@ func refreshingTokenSourceNotify(ctx context.Context, db *ent.Client, userID uin
}

func scavengeRetrieveError(err error) (*oauth2.RetrieveError, bool) {
// unwrap all *url.Error
if urlErr, ok := err.(*url.Error); ok {
err = errors.Unwrap(urlErr)
log.Debug().Type("errType", err).Msg("unwrapped *url.Error")
}
if rErr, ok := err.(*oauth2.RetrieveError); ok {
return rErr, ok
}
errString := err.Error()
log.Debug().Str("errString", errString).Msg("oauth2.RetrieveError?")
log.Debug().Str("errString", errString).Type("errType", err).Msg("oauth2.RetrieveError?")
if strings.Contains(errString, "oauth2: cannot fetch token: ") {
rIdx := strings.Index(errString, "\nResponse: ")
stringBody := errString[rIdx+len("\nResponse: "):]
Expand Down

0 comments on commit f626fa5

Please sign in to comment.