Skip to content

Commit

Permalink
fix(baidu_netdisk): retry logic in request (close #5262)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 22, 2023
1 parent 882112e commit 106cf72
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions drivers/baidu_netdisk/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package baidu_netdisk

import (
"errors"
"fmt"
"net/http"
"net/url"
Expand All @@ -22,7 +23,7 @@ import (

func (d *BaiduNetdisk) refreshToken() error {
err := d._refreshToken()
if err != nil && err == errs.EmptyToken {
if err != nil && errors.Is(err, errs.EmptyToken) {
err = d._refreshToken()
}
return err
Expand Down Expand Up @@ -74,21 +75,16 @@ func (d *BaiduNetdisk) request(furl string, method string, callback base.ReqCall
log.Info("refreshing baidu_netdisk token.")
err2 := d.refreshToken()
if err2 != nil {
return err2
return retry.Unrecoverable(err2)
}
}

err2 := fmt.Errorf("req: [%s] ,errno: %d, refer to https://pan.baidu.com/union/doc/", furl, errno)
if !utils.SliceContains([]int{2}, errno) {
err2 = retry.Unrecoverable(err2)
}
return err2
return fmt.Errorf("req: [%s] ,errno: %d, refer to https://pan.baidu.com/union/doc/", furl, errno)
}
result = res.Body()
return nil
},
retry.LastErrorOnly(true),
retry.Attempts(5),
retry.Attempts(3),
retry.Delay(time.Second),
retry.DelayType(retry.BackOffDelay))
return result, err
Expand Down

0 comments on commit 106cf72

Please sign in to comment.