OSDN Git Service

fix error exhibition (#1229)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Fri, 3 Aug 2018 09:13:12 +0000 (17:13 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 3 Aug 2018 09:13:12 +0000 (17:13 +0800)
api/api.go
api/errors.go
net/http/httpjson/io.go

index 0ccfa3b..0024e00 100644 (file)
@@ -72,7 +72,11 @@ func FormatErrResp(err error) (response Response) {
        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
 }
@@ -80,9 +84,6 @@ func FormatErrResp(err error) (response Response) {
 //NewErrorResponse error response
 func NewErrorResponse(err error) Response {
        response := FormatErrResp(err)
-       if response.Msg == "" {
-               response.Msg = err.Error()
-       }
        return response
 }
 
index 2e24c1f..92b9d0b 100644 (file)
@@ -17,6 +17,11 @@ import (
        "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
@@ -38,6 +43,8 @@ func isTemporary(info httperror.Info, err error) bool {
 }
 
 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"},
index 77e5da1..9f9010d 100644 (file)
@@ -24,7 +24,7 @@ func Read(r io.Reader, v interface{}) error {
        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)