uses newPathError

This commit is contained in:
Christoph Polcin 2014-10-24 11:38:11 +02:00
parent 3a09040ecb
commit eb64a8f4bd
2 changed files with 5 additions and 9 deletions

View File

@ -69,7 +69,6 @@ func getProps(r *response, status string) *props {
}
func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
// TODO return newPathError
path = FixSlashes(path)
files := make([]os.FileInfo, 0)
skipSelf := true
@ -115,21 +114,23 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
</d:propfind>`,
&response{},
parse)
if err != nil {
err = &os.PathError{"ReadDir", path, err}
}
return files, err
}
func (c *Client) Remove(path string) error {
// TODO return newPathError
rs, err := c.reqDo("DELETE", path, nil)
if err != nil {
return err
return newPathError("Remove", path, 400)
}
defer rs.Body.Close()
if rs.StatusCode == 200 {
return nil
} else {
return Error(rs)
return newPathError("Remove", path, rs.StatusCode)
}
}

View File

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
@ -17,10 +16,6 @@ func log(msg interface{}) {
fmt.Println(msg)
}
func Error(r *http.Response) error {
return errors.New(fmt.Sprintf("%s - %s %s", r.Status, r.Request.Method, r.Request.URL.String()))
}
func newPathError(op string, path string, statusCode int) error {
return &os.PathError{op, path, errors.New(fmt.Sprintf("%d", statusCode))}
}