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

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"net/http"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -17,10 +16,6 @@ func log(msg interface{}) {
fmt.Println(msg) 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 { func newPathError(op string, path string, statusCode int) error {
return &os.PathError{op, path, errors.New(fmt.Sprintf("%d", statusCode))} return &os.PathError{op, path, errors.New(fmt.Sprintf("%d", statusCode))}
} }