aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-08-27 00:55:31 +0800
committerFelix Lange <fjl@twurst.com>2015-08-27 00:55:31 +0800
commit3df6f3fc14e3a6947cf7217101a55550fc6212f9 (patch)
tree363cc81b7c758a398818aebd6e092dfd499f6843 /rpc
parent847794a321e9bc46d9b9a9d7c90a520a0fb75c19 (diff)
parentf448310eef5abf1dfd10b25bfd22466cb5477dfd (diff)
downloadgo-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar.gz
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar.bz2
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar.lz
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar.xz
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.tar.zst
go-tangerine-3df6f3fc14e3a6947cf7217101a55550fc6212f9.zip
Merge pull request #1721 from bas-vk/console-error-parsing
Improved console error handling
Diffstat (limited to 'rpc')
-rw-r--r--rpc/jeth.go9
-rw-r--r--rpc/shared/types.go6
2 files changed, 7 insertions, 8 deletions
diff --git a/rpc/jeth.go b/rpc/jeth.go
index 757f6b7eb..ae2603ae4 100644
--- a/rpc/jeth.go
+++ b/rpc/jeth.go
@@ -44,11 +44,12 @@ func NewJeth(ethApi shared.EthereumApi, re *jsre.JSRE, client comms.EthereumClie
}
func (self *Jeth) err(call otto.FunctionCall, code int, msg string, id interface{}) (response otto.Value) {
- errObj := fmt.Sprintf("{\"message\": \"%s\", \"code\": %d}", msg, code)
- retResponse := fmt.Sprintf("ret_response = JSON.parse('{\"jsonrpc\": \"%s\", \"id\": %v, \"error\": %s}');", shared.JsonRpcVersion, id, errObj)
+ m := shared.NewRpcErrorResponse(id, shared.JsonRpcVersion, code, fmt.Errorf(msg))
+ errObj, _ := json.Marshal(m.Error)
+ errRes, _ := json.Marshal(m)
- call.Otto.Run("ret_error = " + errObj)
- res, _ := call.Otto.Run(retResponse)
+ call.Otto.Run("ret_error = " + string(errObj))
+ res, _ := call.Otto.Run("ret_response = " + string(errRes))
return res
}
diff --git a/rpc/shared/types.go b/rpc/shared/types.go
index 659b74bf6..dd9a60aab 100644
--- a/rpc/shared/types.go
+++ b/rpc/shared/types.go
@@ -74,11 +74,9 @@ type ErrorObject struct {
}
// Create RPC error response, this allows for custom error codes
-func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *interface{} {
- var response interface{}
-
+func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *ErrorResponse {
jsonerr := &ErrorObject{errCode, err.Error()}
- response = ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr}
+ response := ErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: jsonerr}
glog.V(logger.Detail).Infof("Generated error response: %s", response)
return &response