mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
Make Response.Path return the path on error
This commit is contained in:
parent
373663f9ee
commit
ed52608852
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user