Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

API: better cid and fid error handling #139

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions jprov/server/file_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -92,6 +93,22 @@ func writeResponse(w http.ResponseWriter, upload types.Upload, fid, cid string)
return json.NewEncoder(w).Encode(resp)
}

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)
}

resp := types.UploadResponse{
CID: cid,
FID: fid,
Expand Down
2 changes: 0 additions & 2 deletions jprov/testutils/testFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())}
}

Loading