fixes #33, remove missingPropError error

This commit is contained in:
AlmogBaku 2020-03-29 01:51:45 +03:00 committed by Simon Ser
parent abadf534f4
commit 1b725cb0b9
2 changed files with 4 additions and 17 deletions

View File

@ -124,7 +124,7 @@ func (h *Handler) handleQuery(w http.ResponseWriter, query *addressbookQuery) er
var q AddressBookQuery var q AddressBookQuery
if query.Prop != nil { if query.Prop != nil {
var addressData addressDataReq 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 return err
} }
req, err := decodeAddressDataReq(&addressData) req, err := decodeAddressDataReq(&addressData)
@ -176,7 +176,7 @@ func (h *Handler) handleMultiget(w http.ResponseWriter, multiget *addressbookMul
var dataReq AddressDataRequest var dataReq AddressDataRequest
if multiget.Prop != nil { if multiget.Prop != nil {
var addressData addressDataReq 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 return err
} }
decoded, err := decodeAddressDataReq(&addressData) decoded, err := decodeAddressDataReq(&addressData)

View File

@ -143,19 +143,6 @@ func (resp *Response) Path() (string, error) {
return resp.Hrefs[0].Path, nil 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 { func (resp *Response) DecodeProp(values ...interface{}) error {
for _, v := range values { for _, v := range values {
// TODO wrap errors with more context (XML name) // TODO wrap errors with more context (XML name)
@ -176,7 +163,7 @@ func (resp *Response) DecodeProp(values ...interface{}) error {
} }
return raw.Decode(v) return raw.Decode(v)
} }
return &missingPropError{name} return HTTPErrorf(http.StatusNotFound, "missing property %s", name)
} }
return nil return nil
@ -254,7 +241,7 @@ func (p *Prop) Decode(v interface{}) error {
raw := p.Get(name) raw := p.Get(name)
if raw == nil { if raw == nil {
return &missingPropError{name} return HTTPErrorf(http.StatusNotFound, "missing property %s", name)
} }
return raw.Decode(v) return raw.Decode(v)