diff --git a/jprov/server/file_server.go b/jprov/server/file_server.go index 9bfdfcd..7cb0e87 100644 --- a/jprov/server/file_server.go +++ b/jprov/server/file_server.go @@ -69,6 +69,7 @@ func saveFile(file multipart.File, handler *multipart.FileHeader, sender string, if msg.Err != nil { ctx.Logger.Error(msg.Err.Error()) + return err } if err = writeResponse(*w, *msg, fid, cid); err != nil { @@ -97,6 +98,22 @@ func writeResponse(w http.ResponseWriter, upload types.Upload, fid, cid string) FID: fid, } + if len(cid) == 0 { + e := fmt.Errorf("cid: '%s' is empty", cid) + resp := types.ErrorResponse{ + Error: e.Error(), + } + return json.NewEncoder(w).Encode(resp) + } + + if len(fid) == 0 { + e := fmt.Errorf("file with cid '%s' has empty fid: '%s'", cid, fid) + resp := types.ErrorResponse{ + Error: e.Error(), + } + return json.NewEncoder(w).Encode(resp) + } + return json.NewEncoder(w).Encode(resp) } diff --git a/jprov/testutils/testFile.go b/jprov/testutils/testFile.go index 3227b1a..d70a8b8 100644 --- a/jprov/testutils/testFile.go +++ b/jprov/testutils/testFile.go @@ -9,7 +9,6 @@ import ( storagetypes "github.com/jackalLabs/canine-chain/v3/x/storage/types" - "github.com/wealdtech/go-merkletree" "github.com/wealdtech/go-merkletree/sha3" ) @@ -56,4 +55,3 @@ func (m *MerkleFile) GetJsonProof() []byte { func (m *MerkleFile) GenerateActiveDeal() storagetypes.ActiveDeals { return storagetypes.ActiveDeals{Blocktoprove: "0", Merkle: hex.EncodeToString(m.tree.Root())} } -