Skip to content

Commit

Permalink
Handle parsing error instead of logging errors (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
shleikes authored Nov 18, 2024
1 parent 8803889 commit 0625d61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context, cmdFlags common.Con
return fiberCtx.Status(fiber.StatusOK).JSON(common.JsonRpcMethodNotFoundError)
}

if _, ok := err.(*json.SyntaxError); ok {
return fiberCtx.Status(fiber.StatusBadRequest).JSON(common.JsonRpcParseError)
}

// Get unique GUID response
errMasking := apil.logger.GetUniqueGuidResponseForError(err, msgSeed)

Expand Down
10 changes: 10 additions & 0 deletions protocol/common/return_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ var JsonRpcRateLimitError = JsonRPCErrorMessage{
},
}

var JsonRpcParseError = JsonRPCErrorMessage{
JsonRPC: "2.0",
Id: -1,
Error: JsonRPCError{
Code: -32700,
Message: "Parse error",
Data: "Failed to parse the request body as JSON",
},
}

var JsonRpcSubscriptionNotFoundError = JsonRPCErrorMessage{
JsonRPC: "2.0",
Id: 1,
Expand Down

0 comments on commit 0625d61

Please sign in to comment.