mirror of
https://github.com/rclone/rclone.git
synced 2025-04-22 03:48:51 +08:00
lib/rest: retry errors due to failed JSON decoding - fixes #8383
These errors are almost always caused by an overloaded proxy somewhere in the chain returning HTML so they are worth retrying.
This commit is contained in:
parent
4aaef7472d
commit
53bbe891d3
@ -17,6 +17,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/fserrors"
|
||||
"github.com/rclone/rclone/lib/readers"
|
||||
)
|
||||
|
||||
@ -189,7 +190,13 @@ func checkDrainAndClose(r io.ReadCloser, err *error) {
|
||||
func DecodeJSON(resp *http.Response, result interface{}) (err error) {
|
||||
defer checkDrainAndClose(resp.Body, &err)
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
return decoder.Decode(result)
|
||||
err = decoder.Decode(result)
|
||||
if err != nil {
|
||||
// Retry this as it is likely some overloaded server sending HTML instead of JSON
|
||||
contentType := resp.Header.Get("Content-Type")
|
||||
err = fserrors.RetryError(fmt.Errorf("failed to decode JSON from Content-Type: %q: %v", contentType, err))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// DecodeXML decodes resp.Body into result
|
||||
|
Loading…
x
Reference in New Issue
Block a user