mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
fixes #33, remove missingPropError error
This commit is contained in:
parent
abadf534f4
commit
1b725cb0b9
@ -124,7 +124,7 @@ func (h *Handler) handleQuery(w http.ResponseWriter, query *addressbookQuery) er
|
||||
var q AddressBookQuery
|
||||
if query.Prop != nil {
|
||||
var addressData addressDataReq
|
||||
if err := query.Prop.Decode(&addressData); err != nil && !internal.IsMissingProp(err) {
|
||||
if err := query.Prop.Decode(&addressData); err != nil && !internal.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
req, err := decodeAddressDataReq(&addressData)
|
||||
@ -176,7 +176,7 @@ func (h *Handler) handleMultiget(w http.ResponseWriter, multiget *addressbookMul
|
||||
var dataReq AddressDataRequest
|
||||
if multiget.Prop != nil {
|
||||
var addressData addressDataReq
|
||||
if err := multiget.Prop.Decode(&addressData); err != nil && !internal.IsMissingProp(err) {
|
||||
if err := multiget.Prop.Decode(&addressData); err != nil && !internal.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
decoded, err := decodeAddressDataReq(&addressData)
|
||||
|
@ -143,19 +143,6 @@ func (resp *Response) Path() (string, error) {
|
||||
return resp.Hrefs[0].Path, nil
|
||||
}
|
||||
|
||||
type missingPropError struct {
|
||||
XMLName xml.Name
|
||||
}
|
||||
|
||||
func (err *missingPropError) Error() string {
|
||||
return fmt.Sprintf("webdav: missing prop %q %q", err.XMLName.Space, err.XMLName.Local)
|
||||
}
|
||||
|
||||
func IsMissingProp(err error) bool {
|
||||
_, ok := err.(*missingPropError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (resp *Response) DecodeProp(values ...interface{}) error {
|
||||
for _, v := range values {
|
||||
// TODO wrap errors with more context (XML name)
|
||||
@ -176,7 +163,7 @@ func (resp *Response) DecodeProp(values ...interface{}) error {
|
||||
}
|
||||
return raw.Decode(v)
|
||||
}
|
||||
return &missingPropError{name}
|
||||
return HTTPErrorf(http.StatusNotFound, "missing property %s", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -254,7 +241,7 @@ func (p *Prop) Decode(v interface{}) error {
|
||||
|
||||
raw := p.Get(name)
|
||||
if raw == nil {
|
||||
return &missingPropError{name}
|
||||
return HTTPErrorf(http.StatusNotFound, "missing property %s", name)
|
||||
}
|
||||
|
||||
return raw.Decode(v)
|
||||
|
Loading…
Reference in New Issue
Block a user