From 3ba85d66a2ca06a1910a363ab3c695eae04fa052 Mon Sep 17 00:00:00 2001 From: toranger Date: Wed, 29 May 2019 15:49:57 +0800 Subject: [PATCH] Add the error when return 200OK but body contains the error --- object.go | 6 ++++++ object_part.go | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/object.go b/object.go index 452dd65..edde8ea 100644 --- a/object.go +++ b/object.go @@ -231,6 +231,12 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O result: &res, } resp, err := s.client.send(ctx, &sendOpt) + // If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error. + if err == nil && resp.StatusCode == 200 { + if res.ETag == "" { + return &res, resp, errors.New("response 200 OK, but body contains an error") + } + } return &res, resp, err } diff --git a/object_part.go b/object_part.go index 7e95d14..196fa7a 100644 --- a/object_part.go +++ b/object_part.go @@ -3,6 +3,7 @@ package cos import ( "context" "encoding/xml" + "errors" "fmt" "io" "net/http" @@ -162,6 +163,12 @@ func (s *ObjectService) CompleteMultipartUpload(ctx context.Context, name, uploa result: &res, } resp, err := s.client.send(ctx, &sendOpt) + // If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error. + if err == nil && resp.StatusCode == 200 { + if res.ETag == "" { + return &res, resp, errors.New("response 200 OK, but body contains an error") + } + } return &res, resp, err }