From 6ddef03790971e346fa0a7d33a462f39348bc6cc Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 19 May 2023 09:05:40 -0400 Subject: [PATCH] fix: if uploading returns a 500 and its a slab error, treat as a 404 --- service/files/files.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/service/files/files.go b/service/files/files.go index bd7b018..d0f81f6 100644 --- a/service/files/files.go +++ b/service/files/files.go @@ -59,16 +59,22 @@ func Upload(r io.ReadSeeker, size int64) (model.Upload, error) { return upload, err } - if objectExistsResult.StatusCode() == 500 { - return upload, errors.New(fmt.Sprintf("error fetching file: %s", objectExistsResult.String())) + statusCode := objectExistsResult.StatusCode() + + if statusCode == 500 { + bodyErr := objectExistsResult.String() + if !strings.Contains(bodyErr, "no slabs found") { + shared.GetLogger().Error("Failed fetching object", zap.String("error", objectExistsResult.String())) + return upload, errors.New(fmt.Sprintf("error fetching file: %s", objectExistsResult.String())) + } + + statusCode = 404 } - if objectExistsResult.StatusCode() != 404 { - return upload, errors.New("file already exists in network, but missing in database") - } - - if err != nil { - return upload, err + if statusCode != 404 { + msg := "file already exists in network, but missing in database" + shared.GetLogger().Error(msg) + return upload, errors.New(msg) } ret, err := client.R().SetBody(r).Put(fmt.Sprintf("/worker/objects/%s", hashHex))