mirror of
https://github.com/rclone/rclone.git
synced 2025-01-05 05:49:33 +01:00
b2: fix decoding of 404 errors producing "Couldn't decode error response: EOF"
See: https://forum.rclone.org/t/move-to-b2-creates-empty-file-versions/23420/
This commit is contained in:
parent
cb30a8c80e
commit
ee87bf19c8
@ -9,6 +9,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
gohash "hash"
|
gohash "hash"
|
||||||
"io"
|
"io"
|
||||||
@ -344,11 +345,17 @@ func (f *Fs) shouldRetry(ctx context.Context, resp *http.Response, err error) (b
|
|||||||
|
|
||||||
// errorHandler parses a non 2xx error response into an error
|
// errorHandler parses a non 2xx error response into an error
|
||||||
func errorHandler(resp *http.Response) error {
|
func errorHandler(resp *http.Response) error {
|
||||||
|
body, err := rest.ReadBody(resp)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error reading error out of body")
|
||||||
|
}
|
||||||
// Decode error response
|
// Decode error response
|
||||||
errResponse := new(api.Error)
|
errResponse := new(api.Error)
|
||||||
err := rest.DecodeJSON(resp, &errResponse)
|
if len(body) > 0 {
|
||||||
if err != nil {
|
err := json.Unmarshal(body, &errResponse)
|
||||||
fs.Debugf(nil, "Couldn't decode error response: %v", err)
|
if err != nil {
|
||||||
|
fs.Debugf(nil, "Couldn't decode error response: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if errResponse.Code == "" {
|
if errResponse.Code == "" {
|
||||||
errResponse.Code = "unknown"
|
errResponse.Code = "unknown"
|
||||||
@ -357,7 +364,7 @@ func errorHandler(resp *http.Response) error {
|
|||||||
errResponse.Status = resp.StatusCode
|
errResponse.Status = resp.StatusCode
|
||||||
}
|
}
|
||||||
if errResponse.Message == "" {
|
if errResponse.Message == "" {
|
||||||
errResponse.Message = "Unknown " + resp.Status
|
errResponse.Message = fmt.Sprintf("Unknown: %s: %s", resp.Status, body)
|
||||||
}
|
}
|
||||||
return errResponse
|
return errResponse
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user