Cleaned up fees and errors a bit from feedback
This commit is contained in:
+4
-6
@@ -6,6 +6,7 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
)
|
||||
|
||||
@@ -40,8 +41,7 @@ func unwrap(i interface{}) interface{} {
|
||||
|
||||
func ErrUnknownTxType(tx interface{}) TMError {
|
||||
msg := fmt.Sprintf("%T", unwrap(tx))
|
||||
w := errors.Wrap(errUnknownTxType, msg)
|
||||
return WithCode(w, abci.CodeType_UnknownRequest)
|
||||
return WithMessage(msg, errUnknownTxType, abci.CodeType_UnknownRequest)
|
||||
}
|
||||
func IsUnknownTxTypeErr(err error) bool {
|
||||
return IsSameError(errUnknownTxType, err)
|
||||
@@ -49,16 +49,14 @@ func IsUnknownTxTypeErr(err error) bool {
|
||||
|
||||
func ErrInvalidFormat(expected string, tx interface{}) TMError {
|
||||
msg := fmt.Sprintf("%T not %s", unwrap(tx), expected)
|
||||
w := errors.Wrap(errInvalidFormat, msg)
|
||||
return WithCode(w, abci.CodeType_UnknownRequest)
|
||||
return WithMessage(msg, errInvalidFormat, abci.CodeType_UnknownRequest)
|
||||
}
|
||||
func IsInvalidFormatErr(err error) bool {
|
||||
return IsSameError(errInvalidFormat, err)
|
||||
}
|
||||
|
||||
func ErrUnknownModule(mod string) TMError {
|
||||
w := errors.Wrap(errUnknownModule, mod)
|
||||
return WithCode(w, abci.CodeType_UnknownRequest)
|
||||
return WithMessage(mod, errUnknownModule, abci.CodeType_UnknownRequest)
|
||||
}
|
||||
func IsUnknownModuleErr(err error) bool {
|
||||
return IsSameError(errUnknownModule, err)
|
||||
|
||||
@@ -104,6 +104,13 @@ func WithCode(err error, code abci.CodeType) TMError {
|
||||
}
|
||||
}
|
||||
|
||||
// WithMessage prepends some text to the error, then calls WithCode
|
||||
// It wraps the original error, so IsSameError will still match on err
|
||||
func WithMessage(prefix string, err error, code abci.CodeType) TMError {
|
||||
e2 := errors.WithMessage(err, prefix)
|
||||
return WithCode(e2, code)
|
||||
}
|
||||
|
||||
// New adds a stacktrace if necessary and sets the code and msg,
|
||||
// overriding the state if err was already TMError
|
||||
func New(msg string, code abci.CodeType) TMError {
|
||||
|
||||
Reference in New Issue
Block a user