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.
This commit is contained in:
John C. Vernaleo 2013-11-18 13:23:05 -05:00
parent 9dbf75029f
commit 606262514b

View file

@ -7,6 +7,7 @@ package btcjson
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
) )
// Message contains a message to be sent to the bitcoin client. // 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 var objmap map[string]json.RawMessage
err = json.Unmarshal(message, &objmap) err = json.Unmarshal(message, &objmap)
if err != nil { 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 return result, err
} }
// Take care of the parts that are the same for all replies. // Take care of the parts that are the same for all replies.