forked from cerc-io/plugeth
Merge pull request #1721 from bas-vk/console-error-parsing
Improved console error handling
This commit is contained in:
commit
3df6f3fc14
@ -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) {
|
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)
|
m := shared.NewRpcErrorResponse(id, shared.JsonRpcVersion, code, fmt.Errorf(msg))
|
||||||
retResponse := fmt.Sprintf("ret_response = JSON.parse('{\"jsonrpc\": \"%s\", \"id\": %v, \"error\": %s}');", shared.JsonRpcVersion, id, errObj)
|
errObj, _ := json.Marshal(m.Error)
|
||||||
|
errRes, _ := json.Marshal(m)
|
||||||
|
|
||||||
call.Otto.Run("ret_error = " + errObj)
|
call.Otto.Run("ret_error = " + string(errObj))
|
||||||
res, _ := call.Otto.Run(retResponse)
|
res, _ := call.Otto.Run("ret_response = " + string(errRes))
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,9 @@ type ErrorObject struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create RPC error response, this allows for custom error codes
|
// Create RPC error response, this allows for custom error codes
|
||||||
func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *interface{} {
|
func NewRpcErrorResponse(id interface{}, jsonrpcver string, errCode int, err error) *ErrorResponse {
|
||||||
var response interface{}
|
|
||||||
|
|
||||||
jsonerr := &ErrorObject{errCode, err.Error()}
|
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)
|
glog.V(logger.Detail).Infof("Generated error response: %s", response)
|
||||||
return &response
|
return &response
|
||||||
|
Loading…
Reference in New Issue
Block a user