mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
internal: add more context to Response.DecodeProp errors
This commit is contained in:
parent
d0fc22a428
commit
1c71a7a1c4
@ -177,7 +177,7 @@ func (resp *Response) DecodeProp(values ...interface{}) error {
|
||||
return err
|
||||
}
|
||||
if err := resp.Err(); err != nil {
|
||||
return err
|
||||
return newPropError(name, err)
|
||||
}
|
||||
for _, propstat := range resp.Propstats {
|
||||
raw := propstat.Prop.Get(name)
|
||||
@ -185,16 +185,26 @@ func (resp *Response) DecodeProp(values ...interface{}) error {
|
||||
continue
|
||||
}
|
||||
if err := propstat.Status.Err(); err != nil {
|
||||
return err
|
||||
return newPropError(name, err)
|
||||
}
|
||||
return raw.Decode(v)
|
||||
if err := raw.Decode(v); err != nil {
|
||||
return newPropError(name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return HTTPErrorf(http.StatusNotFound, "missing property %s", name)
|
||||
return newPropError(name, &HTTPError{
|
||||
Code: http.StatusNotFound,
|
||||
Err: fmt.Errorf("missing property"),
|
||||
})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func newPropError(name xml.Name, err error) error {
|
||||
return fmt.Errorf("property <%v %v>: %w", name.Space, name.Local, err)
|
||||
}
|
||||
|
||||
func (resp *Response) EncodeProp(code int, v interface{}) error {
|
||||
raw, err := EncodeRawXMLElement(v)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user