Skip to content

Commit

Permalink
Convert to proper errors
Browse files Browse the repository at this point in the history
Allow returning different JSON RPC error codes depending on error type
  • Loading branch information
tgerring committed Mar 13, 2015
1 parent 14bdcd2 commit 094f921
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 104 deletions.
18 changes: 9 additions & 9 deletions rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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":
Expand All @@ -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":
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 094f921

Please sign in to comment.