Browse Source

完善错误码

pull/47/head
Sydonian 1 year ago
parent
commit
941f3eb622
3 changed files with 9 additions and 6 deletions
  1. +1
    -0
      consts/errorcode/error_code.go
  2. +3
    -1
      pkgs/cmdtrie/command_trie.go
  3. +5
    -5
      pkgs/mq/client.go

+ 1
- 0
consts/errorcode/error_code.go View File

@@ -3,6 +3,7 @@ package errorcode
const (
OK = "OK"
OperationFailed = "OperationFailed"
DataNotFound = "DataNotFound"
BadArgument = "BadArgument"
TaskNotFound = "TaskNotFound"
)

+ 3
- 1
pkgs/cmdtrie/command_trie.go View File

@@ -10,6 +10,8 @@ import (
"gitlink.org.cn/cloudream/common/utils/reflect2"
)

var ErrCommandNotFound = fmt.Errorf("command not found")

type ExecuteOption struct {
ReplaceEmptyArrayWithNil bool // 如果最后一个参数是空数组,则调用命令的时候传递nil参数
}
@@ -178,7 +180,7 @@ func (t *anyCommandTrie) findCommand(cmdWords []string, argWords []string) (*com
})

if cmd == nil {
return nil, nil, fmt.Errorf("command not found")
return nil, nil, ErrCommandNotFound
}
return cmd, argWords, nil
}


+ 5
- 5
pkgs/mq/client.go View File

@@ -22,12 +22,12 @@ const (
var ErrWaitResponseTimeout = fmt.Errorf("wait response timeout")

type CodeMessageError struct {
code string
message string
Code string
Message string
}

func (e *CodeMessageError) Error() string {
return fmt.Sprintf("code: %s, message: %s", e.code, e.message)
return fmt.Sprintf("code: %s, message: %s", e.Code, e.Message)
}

type SendOption struct {
@@ -315,8 +315,8 @@ func Request[TSvc any, TReq MessageBody, TResp MessageBody](_ func(svc TSvc, msg
errCode, errMsg := resp.GetCodeMessage()
if errCode != errorcode.OK {
return defRet, &CodeMessageError{
code: errCode,
message: errMsg,
Code: errCode,
Message: errMsg,
}
}



Loading…
Cancel
Save