fix(proxyd): Fix compliance with JSON-RPC 2.0 spec by adding optional RPCError.Data (#3683)

* fix: add optional data field to RPCError struct

* fix: formatting lint

* feat(proxyd): add changeset
This commit is contained in:
Chris Wessels 2022-10-11 07:51:02 -07:00 committed by GitHub
parent 7cadaca188
commit 15a59bad99
2 changed files with 15 additions and 1 deletions

@ -57,6 +57,7 @@ func (r *RPCRes) MarshalJSON() ([]byte, error) {
type RPCErr struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data,omitempty"`
HTTPErrorCode int `json:"-"`
}

@ -45,7 +45,7 @@ func TestRPCResJSON(t *testing.T) {
`{"jsonrpc":"2.0","result":null,"id":123}`,
},
{
"error result",
"error result without data",
&RPCRes{
JSONRPC: JSONRPCVersion,
Error: &RPCErr{
@ -56,6 +56,19 @@ func TestRPCResJSON(t *testing.T) {
},
`{"jsonrpc":"2.0","error":{"code":1234,"message":"test err"},"id":123}`,
},
{
"error result with data",
&RPCRes{
JSONRPC: JSONRPCVersion,
Error: &RPCErr{
Code: 1234,
Message: "test err",
Data: "revert",
},
ID: []byte("123"),
},
`{"jsonrpc":"2.0","error":{"code":1234,"message":"test err","data":"revert"},"id":123}`,
},
{
"string ID",
&RPCRes{