fix: if uploading returns a 500 and its a slab error, treat as a 404

This commit is contained in:
Derrick Hammer 2023-05-19 09:05:40 -04:00
parent bef2ed7431
commit 6ddef03790
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 8 deletions

View File

@ -59,16 +59,22 @@ func Upload(r io.ReadSeeker, size int64) (model.Upload, error) {
return upload, err
}
if objectExistsResult.StatusCode() == 500 {
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()))
}
if objectExistsResult.StatusCode() != 404 {
return upload, errors.New("file already exists in network, but missing in database")
statusCode = 404
}
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))