Skip to content

Commit

Permalink
Merge pull request #138 from mysteriumnetwork/generic-timeout-check
Browse files Browse the repository at this point in the history
Add a generic func to check if error is a failure to reach BC
  • Loading branch information
tomasmik authored Sep 29, 2021
2 parents 454a8d2 + 4deeb82 commit 0d7c424
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions client/bc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package client

import (
"context"
"errors"
"math/big"
"net"
"time"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -192,6 +194,25 @@ type EtherClient interface {
SendTransaction(ctx context.Context, tx *types.Transaction) error
}

// IsErrConnectionFailed returns true if the error represents
// a failure to reach blockchain client.
func IsErrConnectionFailed(err error) bool {
if errors.Is(err, context.DeadlineExceeded) {
return true
}

if errors.Is(err, context.Canceled) {
return true
}

var e net.Error
if errors.As(err, &e) {
return e.Timeout()
}

return false
}

// EthClientGetter wraps any eth client.
type EthClientGetter interface {
// Client returns a client to use for making call to the eth blockchain.
Expand Down

0 comments on commit 0d7c424

Please sign in to comment.