Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,10 @@ type responseHandler struct {
metrics metrics.Collector
}

const errCodePanic = -32603
const (
errCodePanic = -32603
errCodeTimeout = -32002
)

type jsonError struct {
Code int `json:"code"`
Expand Down Expand Up @@ -470,6 +473,11 @@ func (w *responseHandler) Write(data []byte) (int, error) {
w.metrics.ServerPanicked(message.Error.Message)
}

// handle possible request timeouts
if message.Error != nil && message.Error.Code == errCodeTimeout {
w.metrics.ApiErrorOccurred()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be emitting this metric any time message.Error != nil?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is generally handled from the handleError function: https://github.com/onflow/flow-evm-gateway/blob/main/api/utils.go#L140-L142.

There are plenty of cases where message.Error != nil and the actual error is simply a user error, e.g.

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32602,
    "message": "too many arguments, want at most 0"
  }
}

Emitting the ApiErrorOccurred metric for such cases, would only cause false alerts.

We are only interested in the special case where message.Error.Code == errCodeTimeout, because in this case, the handleError function never gets called.

}

// It's an error response and requires special treatment.
if message.Error != nil {
// The logic below is taken from:
Expand Down