Skip to content

Commit

Permalink
fix: query error (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kfangw authored and Woosang Son committed Mar 19, 2021
1 parent d4ad039 commit d3e8ed6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions client/errors_query.go
Original file line number Diff line number Diff line change
@@ -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())
}
2 changes: 1 addition & 1 deletion client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3e8ed6

Please sign in to comment.