aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/http/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/http/server.go')
-rw-r--r--rpc/http/server.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/rpc/http/server.go b/rpc/http/server.go
index 965727a4e..a34400a77 100644
--- a/rpc/http/server.go
+++ b/rpc/http/server.go
@@ -84,27 +84,30 @@ func (s *RpcHttpServer) Start() {
}
func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
+ var jsonrpcver string = "2.0"
fn := func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
- rpchttplogger.Debugln("Handling request")
+ rpchttplogger.DebugDetailln("Handling request")
reqParsed, reqerr := JSON.ParseRequestBody(req)
if reqerr != nil {
- JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: rpc.ErrorParseRequest})
+ jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest}
+ JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
return
}
var response interface{}
reserr := api.GetRequestReply(&reqParsed, &response)
if reserr != nil {
- rpchttplogger.Errorln(reserr)
- JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: true, ErrorText: reserr.Error()})
+ rpchttplogger.Warnln(reserr)
+ jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
+ JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: &reqParsed.ID, Error: jsonerr})
return
}
- rpchttplogger.Debugf("Generated response: %T %s", response, response)
- JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
+ rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
+ JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
}
return http.HandlerFunc(fn)