Skip to content

Commit f656754

Browse files
committed
eth: Handle -32603 internal server error in http requests
1 parent 947efd9 commit f656754

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

internal/http.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func IncomingHttpHandler(ctx context.Context, endpoint *Endpoint, w http.Respons
177177
}
178178
}
179179

180+
didGoOffline := false
181+
180182
for i, res := range res.Responses {
181183
method := req.Requests[i].Method
182184

@@ -186,6 +188,27 @@ func IncomingHttpHandler(ctx context.Context, endpoint *Endpoint, w http.Respons
186188
} else {
187189
metrics.RecordRequest(endpoint.Name, provider.Name, "http", method, time.Since(start).Seconds())
188190
}
191+
192+
if !didGoOffline && res.IsError() {
193+
errorCode, errorMessage := res.GetError()
194+
195+
// TODO: These errors are Ethereum specific. We should handle them in a more generic way.
196+
switch errorCode {
197+
case EthErrorRateLimited:
198+
provider.HandleTooManyRequests(nil)
199+
provider.SetStatus(false, errorMessage)
200+
201+
case EthErrorInternalError:
202+
provider.SetStatus(false, errorMessage)
203+
204+
default:
205+
log.Warn("error response", "error_code", errorCode, "error_message", errorMessage, "raw_error", res.Error)
206+
continue
207+
}
208+
209+
// Only go offline once. We still want to return error responses to the client.
210+
didGoOffline = true
211+
}
189212
}
190213

191214
if req.IsBatch {

internal/ws.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ func (proxy *WebSocketProxy) pumpProvider(providerClient *Client) {
174174

175175
errorCode, errorMessage := rpcResponse.GetError()
176176

177+
// TODO: These errors are Ethereum specific. We should handle them in a more generic way.
177178
switch errorCode {
178179
case EthErrorRateLimited:
179180
// Set the provider as offline
180181
err = proxy.provider.HandleTooManyRequests(nil)
181-
proxy.provider.SetStatus(false, err)
182+
proxy.provider.SetStatus(false, errorMessage)
182183

183184
// Forward the error to the client
184185
proxy.Responses <- rpcResponse

0 commit comments

Comments
 (0)