From a9c619c270927456787a638856e315289f9005b7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 9 Dec 2020 01:34:24 -0800 Subject: [PATCH] added error handling for saving --- weed/filer/read_write.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/weed/filer/read_write.go b/weed/filer/read_write.go index 8561d848b..286b073bf 100644 --- a/weed/filer/read_write.go +++ b/weed/filer/read_write.go @@ -6,6 +6,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/wdclient" + "io/ioutil" "math" "net/http" ) @@ -56,7 +57,16 @@ func SaveAs(host string, port int, dir, name string, contentType string, byteBuf if err != nil { return err } - util.CloseResponse(resp) + defer util.CloseResponse(resp) + + b, err := ioutil.ReadAll(resp.Body) + if err != nil { + return err + } + + if resp.StatusCode >= 400 { + return fmt.Errorf("%s: %s %v", target, resp.Status, string(b)) + } return nil