diff options
| author | Chris Lu <chris.lu@gmail.com> | 2016-07-20 23:45:55 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2016-07-20 23:45:55 -0700 |
| commit | cdae9fc680c8e7f99c0ef47dd98f674df76e5078 (patch) | |
| tree | 8189bdfb1f38fce7ddc2a2ff73ab040caeb5f30a /weed/util/http_util.go | |
| parent | 40ba6d2a6f146ab730cc5409c3dbcfb71f7acab9 (diff) | |
| download | seaweedfs-cdae9fc680c8e7f99c0ef47dd98f674df76e5078.tar.xz seaweedfs-cdae9fc680c8e7f99c0ef47dd98f674df76e5078.zip | |
add "weed copy" command to copy files to filer
Diffstat (limited to 'weed/util/http_util.go')
| -rw-r--r-- | weed/util/http_util.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/weed/util/http_util.go b/weed/util/http_util.go index a54fc8779..2379e3b2b 100644 --- a/weed/util/http_util.go +++ b/weed/util/http_util.go @@ -32,6 +32,9 @@ func PostBytes(url string, body []byte) ([]byte, error) { return nil, fmt.Errorf("Post to %s: %v", url, err) } defer r.Body.Close() + if r.StatusCode >= 400 { + return nil, fmt.Errorf("%s: %s", url, r.Status) + } b, err := ioutil.ReadAll(r.Body) if err != nil { return nil, fmt.Errorf("Read response body: %v", err) @@ -45,6 +48,9 @@ func Post(url string, values url.Values) ([]byte, error) { return nil, err } defer r.Body.Close() + if r.StatusCode >= 400 { + return nil, fmt.Errorf("%s: %s", url, r.Status) + } b, err := ioutil.ReadAll(r.Body) if err != nil { return nil, err @@ -59,7 +65,7 @@ func Get(url string) ([]byte, error) { } defer r.Body.Close() b, err := ioutil.ReadAll(r.Body) - if r.StatusCode != 200 { + if r.StatusCode >= 400 { return nil, fmt.Errorf("%s: %s", url, r.Status) } if err != nil { @@ -81,6 +87,9 @@ func Delete(url string, jwt security.EncodedJwt) error { return e } defer resp.Body.Close() + if resp.StatusCode >= 400 { + return fmt.Errorf("%s: %s", url, resp.Status) + } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err |
