if info, ok := respErrFormatter[root]; ok {
response.Code = info.ChainCode
response.Msg = info.Message
- response.ErrorDetail = errors.Detail(err)
+ response.ErrorDetail = err.Error()
+ } else {
+ response.Code = respErrFormatter[ErrDefault].ChainCode
+ response.Msg = respErrFormatter[ErrDefault].Message
+ response.ErrorDetail = err.Error()
}
return response
}
//NewErrorResponse error response
func NewErrorResponse(err error) Response {
response := FormatErrResp(err)
- if response.Msg == "" {
- response.Msg = err.Error()
- }
return response
}
"github.com/bytom/protocol/vm"
)
+var (
+ // ErrDefault is default Bytom API Error
+ ErrDefault = errors.New("Bytom API Error")
+)
+
func isTemporary(info httperror.Info, err error) bool {
switch info.ChainCode {
case "BTM000": // internal server error
}
var respErrFormatter = map[error]httperror.Info{
+ ErrDefault: {500, "BTM000", "Bytom API Error"},
+
// Signers error namespace (2xx)
signers.ErrBadQuorum: {400, "BTM200", "Quorum must be greater than 1 and less than or equal to the length of xpubs"},
signers.ErrBadXPub: {400, "BTM201", "Invalid xpub format"},
err := dec.Decode(v)
if err != nil {
detail := errors.Detail(err)
- if detail == "" {
+ if detail == "" || detail == err.Error() {
detail = "check request parameters for missing and/or incorrect values"
}
return errors.WithDetail(ErrBadRequest, err.Error()+": "+detail)