Convert to proper errors
Allow returning different JSON RPC error codes depending on error type
This commit is contained in:
18
rpc/api.go
18
rpc/api.go
@ -578,7 +578,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
}
|
||||
return p.Call(args, reply)
|
||||
case "eth_flush":
|
||||
return errNotImplemented
|
||||
return NewNotImplementedError(req.Method)
|
||||
case "eth_getBlockByHash":
|
||||
args := new(GetBlockByHashArgs)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
@ -618,7 +618,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return err
|
||||
}
|
||||
if args.Index > int64(len(v.Transactions)) || args.Index < 0 {
|
||||
return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist")
|
||||
return NewValidationError("Index", "does not exist")
|
||||
}
|
||||
*reply = v.Transactions[args.Index]
|
||||
case "eth_getTransactionByBlockNumberAndIndex":
|
||||
@ -632,7 +632,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return err
|
||||
}
|
||||
if args.Index > int64(len(v.Transactions)) || args.Index < 0 {
|
||||
return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist")
|
||||
return NewValidationError("Index", "does not exist")
|
||||
}
|
||||
*reply = v.Transactions[args.Index]
|
||||
case "eth_getUncleByBlockHashAndIndex":
|
||||
@ -646,7 +646,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return err
|
||||
}
|
||||
if args.Index > int64(len(v.Uncles)) || args.Index < 0 {
|
||||
return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist")
|
||||
return NewValidationError("Index", "does not exist")
|
||||
}
|
||||
|
||||
uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false)
|
||||
@ -665,7 +665,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return err
|
||||
}
|
||||
if args.Index > int64(len(v.Uncles)) || args.Index < 0 {
|
||||
return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist")
|
||||
return NewValidationError("Index", "does not exist")
|
||||
}
|
||||
|
||||
uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false)
|
||||
@ -678,7 +678,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
case "eth_compileSolidity":
|
||||
case "eth_compileLLL":
|
||||
case "eth_compileSerpent":
|
||||
return errNotImplemented
|
||||
return NewNotImplementedError(req.Method)
|
||||
case "eth_newFilter":
|
||||
args := new(FilterOptions)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
@ -717,7 +717,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return p.AllLogs(args, reply)
|
||||
case "eth_getWork":
|
||||
case "eth_submitWork":
|
||||
return errNotImplemented
|
||||
return NewNotImplementedError(req.Method)
|
||||
case "db_put":
|
||||
args := new(DbArgs)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
@ -746,7 +746,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return p.HasWhisperIdentity(args.Identity, reply)
|
||||
case "shh_newGroup":
|
||||
case "shh_addToGroup":
|
||||
return errNotImplemented
|
||||
return NewNotImplementedError(req.Method)
|
||||
case "shh_newFilter":
|
||||
args := new(WhisperFilterArgs)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
@ -790,7 +790,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
// }
|
||||
// return p.WatchTx(args, reply)
|
||||
default:
|
||||
return NewErrorWithMessage(errNotImplemented, req.Method)
|
||||
return NewNotImplementedError(req.Method)
|
||||
}
|
||||
|
||||
rpclogger.DebugDetailf("Reply: %T %s", reply, reply)
|
||||
|
Reference in New Issue
Block a user