Add a Error() to the Error struct.

Resolves #6
This commit is contained in:
John C. Vernaleo 2013-09-30 17:13:19 -04:00
parent b0ca6d5903
commit dc9618c9ab
2 changed files with 5 additions and 2 deletions

View file

@ -6,6 +6,7 @@ package btcjson
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
) )
@ -157,6 +158,7 @@ type ListUnSpentResult struct {
type Error struct { type Error struct {
Code int `json:"code,omitempty"` Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"` Message string `json:"message,omitempty"`
Error error `json:"-"`
} }
// jsonWithArgs takes a command, an id, and an interface which contains an // jsonWithArgs takes a command, an id, and an interface which contains an
@ -703,6 +705,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
var jsonErr Error var jsonErr Error
var id interface{} var id interface{}
err = json.Unmarshal(objmap["error"], &jsonErr) err = json.Unmarshal(objmap["error"], &jsonErr)
jsonErr.Error = errors.New(string(jsonErr.Code) + ": " + jsonErr.Message)
if err != nil { if err != nil {
err = fmt.Errorf("Error unmarshalling json reply: %v", err) err = fmt.Errorf("Error unmarshalling json reply: %v", err)
return result, err return result, err

View file

@ -1,6 +1,6 @@
github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 100.00% (332/332) github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 100.00% (332/332)
github.com/conformal/btcjson/jsonapi.go ReadResultCmd 100.00% (63/63) github.com/conformal/btcjson/jsonapi.go ReadResultCmd 100.00% (64/64)
github.com/conformal/btcjson/jsonapi.go JSONToAmount 100.00% (15/15) github.com/conformal/btcjson/jsonapi.go JSONToAmount 100.00% (15/15)
github.com/conformal/btcjson/jsonapi.go JSONGetMethod 100.00% (14/14) github.com/conformal/btcjson/jsonapi.go JSONGetMethod 100.00% (14/14)
github.com/conformal/btcjson/jsonfxns.go jsonRpcSend 100.00% (7/7) github.com/conformal/btcjson/jsonfxns.go jsonRpcSend 100.00% (7/7)
@ -11,5 +11,5 @@ github.com/conformal/btcjson/jsonapi.go IsValidIdType 100.00% (3/3)
github.com/conformal/btcjson/jsonapi.go CreateMessage 100.00% (2/2) github.com/conformal/btcjson/jsonapi.go CreateMessage 100.00% (2/2)
github.com/conformal/btcjson/jsonapi.go RpcCommand 61.54% (8/13) github.com/conformal/btcjson/jsonapi.go RpcCommand 61.54% (8/13)
github.com/conformal/btcjson/jsonapi.go RpcRawCommand 53.33% (8/15) github.com/conformal/btcjson/jsonapi.go RpcRawCommand 53.33% (8/15)
github.com/conformal/btcjson ------------------- 97.51% (470/482) github.com/conformal/btcjson ------------------- 97.52% (471/483)