diff --git a/client/errors_query.go b/client/errors_query.go new file mode 100644 index 0000000000..b2e68ea89f --- /dev/null +++ b/client/errors_query.go @@ -0,0 +1,31 @@ +package client + +import ( + "bytes" + "encoding/json" + "strings" + + "github.com/pkg/errors" +) + +type Error struct { + Codespace string `json:"codespace"` + Code uint32 `json:"code"` + Message string `json:"message"` +} + +func NewQueryError(codespace string, code uint32, desc string) *Error { + return &Error{Codespace: codespace, Code: code, Message: desc} +} + +func (err Error) Error() string { + var buff bytes.Buffer + enc := json.NewEncoder(&buff) + enc.SetEscapeHTML(false) + + if err := enc.Encode(err); err != nil { + panic(errors.Wrap(err, "failed to encode Query error log")) + } + + return strings.TrimSpace(buff.String()) +} diff --git a/client/query.go b/client/query.go index 8d1c98e5a3..277c740d16 100644 --- a/client/query.go +++ b/client/query.go @@ -79,7 +79,7 @@ func (ctx Context) queryABCI(req abci.RequestQuery) (abci.ResponseQuery, error) } if !result.Response.IsOK() { - return abci.ResponseQuery{}, errors.New(result.Response.Log) + return abci.ResponseQuery{}, NewQueryError(result.Response.Codespace, result.Response.Code, result.Response.Log) } // data from trusted node or subspace query doesn't need verification