From dc9618c9ab1ec795fb76aaa3edd3aea94fbdfbf0 Mon Sep 17 00:00:00 2001 From: "John C. Vernaleo" Date: Mon, 30 Sep 2013 17:13:19 -0400 Subject: [PATCH] Add a Error() to the Error struct. Resolves #6 --- jsonapi.go | 3 +++ test_coverage.txt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jsonapi.go b/jsonapi.go index af347d90..af693c89 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -6,6 +6,7 @@ package btcjson import ( "encoding/json" + "errors" "fmt" ) @@ -157,6 +158,7 @@ type ListUnSpentResult struct { type Error struct { Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` + Error error `json:"-"` } // 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 id interface{} err = json.Unmarshal(objmap["error"], &jsonErr) + jsonErr.Error = errors.New(string(jsonErr.Code) + ": " + jsonErr.Message) if err != nil { err = fmt.Errorf("Error unmarshalling json reply: %v", err) return result, err diff --git a/test_coverage.txt b/test_coverage.txt index 34190458..55d1ee00 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,6 +1,6 @@ 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 JSONGetMethod 100.00% (14/14) 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 RpcCommand 61.54% (8/13) 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)