Make Response.Path return the path on error

This commit is contained in:
Apehaenger 2021-01-12 12:57:28 +01:00 committed by GitHub
parent 373663f9ee
commit ed52608852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -135,13 +135,14 @@ func NewOKResponse(path string) *Response {
} }
func (resp *Response) Path() (string, error) { func (resp *Response) Path() (string, error) {
if err := resp.Status.Err(); err != nil { err := resp.Status.Err()
return "", err var path string
if len(resp.Hrefs) == 1 {
path = resp.Hrefs[0].Path
} else if err == nil {
err = fmt.Errorf("webdav: malformed response: expected exactly one href element, got %v", len(resp.Hrefs))
} }
if len(resp.Hrefs) != 1 { return path, err
return "", fmt.Errorf("webdav: malformed response: expected exactly one href element, got %v", len(resp.Hrefs))
}
return resp.Hrefs[0].Path, nil
} }
func (resp *Response) DecodeProp(values ...interface{}) error { func (resp *Response) DecodeProp(values ...interface{}) error {