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 Sangyeop.lee committed Dec 8, 2020
1 parent 4e68457 commit 0cc0556
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions client/context/errors_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package context

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/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (ctx CLIContext) queryABCI(req abci.RequestQuery) (abci.ResponseQuery, erro
}

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 0cc0556

Please sign in to comment.