chore_: fix error http handling

This commit is contained in:
Andrey Bocharnikov 2024-09-26 17:00:35 +04:00
parent c533a59d15
commit 54276ee731
4 changed files with 33 additions and 23 deletions

View File

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

View File

@ -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
}

View File

@ -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

View File

@ -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(),
//})
}
}