From 606262514b013203220f4ae409689448da7feceb Mon Sep 17 00:00:00 2001 From: "John C. Vernaleo" Date: Mon, 18 Nov 2013 13:23:05 -0500 Subject: [PATCH] Improve error messages. Attempt to determine if error when sending a command is due to auth issue and give more useful error in that case. --- jsonapi.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsonapi.go b/jsonapi.go index 5ab57f2c..13e6e889 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -7,6 +7,7 @@ package btcjson import ( "encoding/json" "fmt" + "strings" ) // Message contains a message to be sent to the bitcoin client. @@ -741,7 +742,11 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { var objmap map[string]json.RawMessage err = json.Unmarshal(message, &objmap) if err != nil { - err = fmt.Errorf("Error unmarshalling json reply: %v", err) + if strings.Contains(string(message), "401 Unauthorized.") { + err = fmt.Errorf("Authentication error.") + } else { + err = fmt.Errorf("Error unmarshalling json reply: %v", err) + } return result, err } // Take care of the parts that are the same for all replies.