Skip to content

Commit

Permalink
chore_: fix error http handling
Browse files Browse the repository at this point in the history
  • Loading branch information
friofry committed Sep 26, 2024
1 parent c533a59 commit 54276ee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
10 changes: 7 additions & 3 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.U
ethClients := []ethclient.RPSLimitedEthClientInterface{
ethclient.NewRPSLimitedEthClient(upstreamClient, limiter, rpcName),
}
c.upstream = chain.NewClient(ethClients, upstreamChainID)
providersHealthManager := healthManager.NewProvidersHealthManager(upstreamChainID)
c.BlockchainHealthManager.RegisterProvidersHealthManager(upstreamChainID, providersHealthManager)
c.upstream = chain.NewClient(ethClients, upstreamChainID, providersHealthManager)
}

c.router = newRouter(c.upstreamEnabled)
Expand All @@ -195,7 +197,7 @@ func (c *Client) SetWalletNotifier(notifier func(chainID uint64, message string)
c.walletNotifier = notifier
}

func (c *Client) SubscribeHealthStatus() chan health_manager.BlockchainHealthStatus {
func (c *Client) SubscribeHealthStatus() chan healthManager.BlockchainHealthStatus {
return c.BlockchainHealthManager.Subscribe()
}

Expand Down Expand Up @@ -396,7 +398,9 @@ func (c *Client) UpdateUpstreamURL(url string) error {
ethClients := []ethclient.RPSLimitedEthClientInterface{
ethclient.NewRPSLimitedEthClient(rpcClient, rpsLimiter, hostPortUpstream),
}
c.upstream = chain.NewClient(ethClients, c.UpstreamChainID)
providersHealthManager := healthManager.NewProvidersHealthManager(c.UpstreamChainID)
c.BlockchainHealthManager.RegisterProvidersHealthManager(c.UpstreamChainID, providersHealthManager)
c.upstream = chain.NewClient(ethClients, c.UpstreamChainID, providersHealthManager)
c.upstreamURL = url
c.Unlock()

Expand Down
8 changes: 7 additions & 1 deletion rpc/health-manager/network_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ func IsNotFoundError(err error) bool {
}

func IsHTTPError(err error) (bool, int) {
var httpErr *rpc.HTTPError
var httpErrPtr *rpc.HTTPError
if errors.As(err, &httpErrPtr) {
return true, httpErrPtr.StatusCode
}

var httpErr rpc.HTTPError
if errors.As(err, &httpErr) {
return true, httpErr.StatusCode
}

return false, 0
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/health-manager/providers_health_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (p *ProvidersHealthManager) updateChainStatus() {

func isNonCriticalError(errorType ProviderErrorType) bool {
switch errorType {
case ErrorTypeNone, ErrorTypeRPSLimit, ErrorTypeVMError, ErrorTypeContextCanceled, ErrorTypeNotFound:
case ErrorTypeNone, ErrorTypeNotFound, ErrorTypeVMError, ErrorTypeRPSLimit, ErrorTypeContextCanceled, ErrorTypeContentTooLarge, ErrorTypeMethodNotFound:
return true
default:
return false
Expand Down
36 changes: 18 additions & 18 deletions services/wallet/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,24 +282,24 @@ func (s *Service) handleBlockchainHealthStatus(blockchainHealthCh chan healthMan
Message: string(jsonData),
At: time.Now().Unix(),
})

// send old event
// TODO: remove and use the new event only
blockchainStatusOld := make(map[uint64]string)
for chainID, chainStatus := range blockchainStatus.Status.Chains {
statusStr := string(chainStatus.Status)
blockchainStatusOld[chainID] = statusStr
}
encodedMessage, err := json.Marshal(blockchainStatus)
if err != nil {
continue
}
s.feed.Send(walletevent.Event{
Type: EventBlockchainStatusChanged,
Accounts: []common.Address{},
Message: string(encodedMessage),
At: time.Now().Unix(),
})
//
//// send old event
//// TODO: remove and use the new event only
//blockchainStatusOld := make(map[uint64]string)
//for chainID, chainStatus := range blockchainStatus.Status.Chains {
// statusStr := string(chainStatus.Status)
// blockchainStatusOld[chainID] = statusStr
//}
//encodedMessage, err := json.Marshal(blockchainStatus)
//if err != nil {
// continue
//}
//s.feed.Send(walletevent.Event{
// Type: EventBlockchainStatusChanged,
// Accounts: []common.Address{},
// Message: string(encodedMessage),
// At: time.Now().Unix(),
//})
}
}

Expand Down

0 comments on commit 54276ee

Please sign in to comment.