From fd764d4ff7bd7e75dfdd7f733f50dd3805d4b3f2 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Tue, 16 Jun 2015 13:07:13 +0200 Subject: added comms http --- rpc/shared/types.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'rpc/shared') diff --git a/rpc/shared/types.go b/rpc/shared/types.go index 6a29fa88e..dd38a4559 100644 --- a/rpc/shared/types.go +++ b/rpc/shared/types.go @@ -42,6 +42,18 @@ type ErrorObject struct { // Data interface{} `json:"data"` } +// Create RPC error response, this allows for custom error codes +func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *interface{} { + var response interface{} + + jsonerr := &ErrorObject{errCode, err.Error()} + response = ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr} + + glog.V(logger.Detail).Infof("Generated error response: %s", response) + return &response +} + +// Create RPC response func NewRpcResponse(id interface{}, jsonrpcver string, reply interface{}, err error) *interface{} { var response interface{} -- cgit v1.2.3