Skip to content

Commit

Permalink
add message explanations for errors (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkrolevets committed Apr 26, 2024
1 parent 4d18fa2 commit e9a6439
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkgs/initiator/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"errors"
"fmt"
"io"
"strings"

spec "github.com/ssvlabs/dkg-spec"
"go.uber.org/zap"

"github.com/bloxapp/ssv-dkg/pkgs/wire"
spec "github.com/ssvlabs/dkg-spec"
)

// opReqResult structure to represent http communication messages incoming to initiator from operators
Expand Down Expand Up @@ -82,7 +83,7 @@ func (c *Initiator) SendToAll(method string, msg []byte, operators []*spec.Opera
for i := 0; i < len(operators); i++ {
res := <-resc
if res.err != nil {
errarr = append(errarr, fmt.Errorf("operator ID: %d, %w", res.operatorID, res.err))
errarr = append(errarr, fmt.Errorf("operator ID: %d; message: %w ", res.operatorID, ProcessError(res.err)))
continue
}
final = append(final, res.result)
Expand All @@ -96,3 +97,13 @@ func (c *Initiator) SendToAll(method string, msg []byte, operators []*spec.Opera

return final, finalerr
}

func ProcessError(err error) error {
if strings.Contains(err.Error(), "context deadline exceeded") {
return fmt.Errorf("the requested server is not responding, not a DKG endpoint: %w", err)
}
if strings.Contains(err.Error(), "no such host") {
return fmt.Errorf("the requested server IP is not reachable: %w", err)
}
return err
}

0 comments on commit e9a6439

Please sign in to comment.