Skip to content

Commit

Permalink
Merge pull request ethereum#1721 from bas-vk/console-error-parsing
Browse files Browse the repository at this point in the history
Improved console error handling
  • Loading branch information
fjl committed Aug 26, 2015
2 parents 847794a + f448310 commit 3df6f3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions rpc/jeth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions rpc/shared/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3df6f3f

Please sign in to comment.