Skip to content

Commit

Permalink
feat: process proposals list errors (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Apr 16, 2023
1 parent c9fec6b commit ba25bcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (rpc *RPC) GetAllProposals() ([]types.Proposal, error) {
return nil, err
}

if batchProposals.Message != "" {
return nil, errors.New(batchProposals.Message)
}

proposals = append(proposals, batchProposals.Proposals...)
if len(batchProposals.Proposals) < PaginationLimit {
break
Expand Down Expand Up @@ -75,7 +79,7 @@ func (rpc *RPC) GetVote(proposal, voter string) (*types.VoteRPCResponse, error)
}

func (rpc *RPC) Get(url string, target interface{}) error {
errors := make([]error, len(rpc.URLs))
nodeErrors := make([]error, len(rpc.URLs))

for index, lcd := range rpc.URLs {
fullURL := lcd + url
Expand All @@ -91,7 +95,7 @@ func (rpc *RPC) Get(url string, target interface{}) error {
}

rpc.Logger.Warn().Str("url", fullURL).Err(err).Msg("LCD request failed")
errors[index] = err
nodeErrors[index] = err
}

rpc.Logger.Warn().Str("url", url).Msg("All LCD requests failed")
Expand All @@ -100,7 +104,7 @@ func (rpc *RPC) Get(url string, target interface{}) error {

sb.WriteString("All LCD requests failed:\n")
for index, url := range rpc.URLs {
sb.WriteString(fmt.Sprintf("#%d: %s -> %s\n", index+1, url, errors[index]))
sb.WriteString(fmt.Sprintf("#%d: %s -> %s\n", index+1, url, nodeErrors[index]))
}

return fmt.Errorf(sb.String())
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type ProposalContent struct {
}

type ProposalsRPCResponse struct {
Code int64 `json:"code"`
Message string `json:"message"`
Proposals []Proposal `json:"proposals"`
}

Expand Down

0 comments on commit ba25bcd

Please sign in to comment.