github.com/Finschia/finschia-sdk@v0.48.1/client/errors_query.go (about)

     1  package client
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"strings"
     7  
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  type Error struct {
    12  	Codespace string `json:"codespace"`
    13  	Code      uint32 `json:"code"`
    14  	Message   string `json:"message"`
    15  }
    16  
    17  func NewQueryError(codespace string, code uint32, desc string) *Error {
    18  	return &Error{Codespace: codespace, Code: code, Message: desc}
    19  }
    20  
    21  func (err Error) Error() string {
    22  	var buff bytes.Buffer
    23  	enc := json.NewEncoder(&buff)
    24  	enc.SetEscapeHTML(false)
    25  
    26  	if err := enc.Encode(err); err != nil {
    27  		panic(errors.Wrap(err, "failed to encode Query error log"))
    28  	}
    29  
    30  	return strings.TrimSpace(buff.String())
    31  }