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

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed May 13, 2024
1 parent 505ef3b commit 7a82e33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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 Down Expand Up @@ -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)
}

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

0 comments on commit 7a82e33

Please sign in to comment.