forked from TrueCloudLab/rclone
webdav: read the body of messages into the error if XML parse fails
This commit is contained in:
parent
f073db81b1
commit
b07e51cf73
1 changed files with 8 additions and 2 deletions
|
@ -19,6 +19,7 @@ package webdav
|
||||||
// For example the ownCloud WebDAV server does it that way.
|
// For example the ownCloud WebDAV server does it that way.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -209,11 +210,16 @@ func (f *Fs) readMetaDataForPath(path string) (info *api.Prop, err error) {
|
||||||
|
|
||||||
// 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 when trying to read error from body")
|
||||||
|
}
|
||||||
// Decode error response
|
// Decode error response
|
||||||
errResponse := new(api.Error)
|
errResponse := new(api.Error)
|
||||||
err := rest.DecodeXML(resp, &errResponse)
|
err = xml.Unmarshal(body, &errResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Debugf(nil, "Couldn't decode error response: %v", err)
|
// set the Message to be the body if can't parse the XML
|
||||||
|
errResponse.Message = strings.TrimSpace(string(body))
|
||||||
}
|
}
|
||||||
errResponse.Status = resp.Status
|
errResponse.Status = resp.Status
|
||||||
errResponse.StatusCode = resp.StatusCode
|
errResponse.StatusCode = resp.StatusCode
|
||||||
|
|
Loading…
Reference in a new issue