Browse Source

better error message for unknown RPC method calls

pull/43/merge
Jae Kwon 10 years ago
parent
commit
d8766e1d37
2 changed files with 7 additions and 3 deletions
  1. +1
    -1
      rpc/core/blocks.go
  2. +6
    -2
      rpc/handlers.go

+ 1
- 1
rpc/core/blocks.go View File

@ -32,7 +32,7 @@ func BlockchainInfo(minHeight, maxHeight uint) (*ResponseBlockchainInfo, error)
func GetBlock(height uint) (*ResponseGetBlock, error) {
if height == 0 {
return nil, fmt.Errorf("height must be greater than 1")
return nil, fmt.Errorf("height must be greater than 0")
}
if height > blockStore.Height() {
return nil, fmt.Errorf("height must be less than the current blockchain height")


+ 6
- 2
rpc/handlers.go View File

@ -35,7 +35,7 @@ var funcMap = map[string]*FuncWrapper{
func initHandlers() {
// HTTP endpoints
for funcName, funcInfo := range funcMap {
http.HandleFunc("/"+funcName, toHttpHandler(funcInfo))
http.HandleFunc("/"+funcName, toHTTPHandler(funcInfo))
}
// JSONRPC endpoints
@ -95,6 +95,10 @@ func JSONRPCHandler(w http.ResponseWriter, r *http.Request) {
}
funcInfo := funcMap[request.Method]
if funcInfo == nil {
WriteRPCResponse(w, NewRPCResponse(nil, "RPC method unknown: "+request.Method))
return
}
args, err := jsonParamsToArgs(funcInfo, request.Params)
if err != nil {
WriteRPCResponse(w, NewRPCResponse(nil, err.Error()))
@ -139,7 +143,7 @@ func _jsonObjectToArg(ty reflect.Type, object interface{}) (reflect.Value, error
// rpc.http
// convert from a function name to the http handler
func toHttpHandler(funcInfo *FuncWrapper) func(http.ResponseWriter, *http.Request) {
func toHTTPHandler(funcInfo *FuncWrapper) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
args, err := httpParamsToArgs(funcInfo, r)
if err != nil {


Loading…
Cancel
Save