internal: add more context to Response.DecodeProp errors

This commit is contained in:
Simon Ser 2022-05-31 17:04:44 +02:00
parent d0fc22a428
commit 1c71a7a1c4

View File

@ -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 {