diff options
| author | tnextday <fw2k4@163.com> | 2015-12-03 16:27:02 +0800 |
|---|---|---|
| committer | tnextday <fw2k4@163.com> | 2015-12-03 16:27:02 +0800 |
| commit | daac5de1bae20de28082367db44b7b7afa9e4aaf (patch) | |
| tree | 77b9ca3beb5f33f736b5a66da8ecf4a53ed1e576 /go/util/http_util.go | |
| parent | a9a336fdff076211e7c94a4243b430219e5d891c (diff) | |
| download | seaweedfs-daac5de1bae20de28082367db44b7b7afa9e4aaf.tar.xz seaweedfs-daac5de1bae20de28082367db44b7b7afa9e4aaf.zip | |
more check in `http_util.Delete`
add status code in `DeleteResult` struct
operation.DeleteFiles maybe unsafe, so `ChunkManifest.DeleteChunks` manually delete each chunks
Diffstat (limited to 'go/util/http_util.go')
| -rw-r--r-- | go/util/http_util.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/go/util/http_util.go b/go/util/http_util.go index 7854302ab..d56aaa39a 100644 --- a/go/util/http_util.go +++ b/go/util/http_util.go @@ -9,7 +9,10 @@ import ( "net/url" "strings" + "encoding/json" + "github.com/chrislusf/seaweedfs/go/security" + "github.com/syndtr/goleveldb/leveldb/errors" ) var ( @@ -79,10 +82,21 @@ func Delete(url string, jwt security.EncodedJwt) error { return e } defer resp.Body.Close() - if _, err := ioutil.ReadAll(resp.Body); err != nil { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { return err } - return nil + switch resp.StatusCode { + case http.StatusNotFound, http.StatusAccepted, http.StatusOK: + return nil + } + m := make(map[string]interface{}) + if e := json.Unmarshal(body, m); e == nil { + if s, ok := m["error"].(string); ok { + return errors.New(s) + } + } + return errors.New(string(body)) } func GetBufferStream(url string, values url.Values, allocatedBytes []byte, eachBuffer func([]byte)) error { |
