aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/json.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-07-12 23:42:44 +0800
committerFelix Lange <fjl@twurst.com>2016-07-23 05:21:27 +0800
commitbb01bea4e276dad359815c682a2dee730737f4dc (patch)
tree9d290506199e836275f39668fff7edfde842e794 /rpc/json.go
parentc145589f25445b9fb78e4556b17cde29df5b37bb (diff)
downloadgo-tangerine-bb01bea4e276dad359815c682a2dee730737f4dc.tar.gz
go-tangerine-bb01bea4e276dad359815c682a2dee730737f4dc.tar.zst
go-tangerine-bb01bea4e276dad359815c682a2dee730737f4dc.zip
rpc: fix bad method error for batch requests
If a batch request contained an invalid method, the server would reply with a non-batch error response. Fix this by tracking an error for each batch element.
Diffstat (limited to 'rpc/json.go')
-rw-r--r--rpc/json.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/rpc/json.go b/rpc/json.go
index 151ed546e..ee931bc87 100644
--- a/rpc/json.go
+++ b/rpc/json.go
@@ -182,12 +182,12 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, RPCError) {
method: unsubscribeMethod, params: in.Payload}}, false, nil
}
- // regular RPC call
elems := strings.Split(in.Method, serviceMethodSeparator)
if len(elems) != 2 {
return nil, false, &methodNotFoundError{in.Method, ""}
}
+ // regular RPC call
if len(in.Payload) == 0 {
return []rpcRequest{rpcRequest{service: elems[0], method: elems[1], id: &in.Id}}, false, nil
}
@@ -236,15 +236,15 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, RPCErro
continue
}
- elems := strings.Split(r.Method, serviceMethodSeparator)
- if len(elems) != 2 {
- return nil, true, &methodNotFoundError{r.Method, ""}
- }
-
if len(r.Payload) == 0 {
- requests[i] = rpcRequest{service: elems[0], method: elems[1], id: id, params: nil}
+ requests[i] = rpcRequest{id: id, params: nil}
+ } else {
+ requests[i] = rpcRequest{id: id, params: r.Payload}
+ }
+ if elem := strings.Split(r.Method, serviceMethodSeparator); len(elem) == 2 {
+ requests[i].service, requests[i].method = elem[0], elem[1]
} else {
- requests[i] = rpcRequest{service: elems[0], method: elems[1], id: id, params: r.Payload}
+ requests[i].err = &methodNotFoundError{r.Method, ""}
}
}