| @@ -3,6 +3,7 @@ package errorcode | |||||
| const ( | const ( | ||||
| OK = "OK" | OK = "OK" | ||||
| OperationFailed = "OperationFailed" | OperationFailed = "OperationFailed" | ||||
| DataNotFound = "DataNotFound" | |||||
| BadArgument = "BadArgument" | BadArgument = "BadArgument" | ||||
| TaskNotFound = "TaskNotFound" | TaskNotFound = "TaskNotFound" | ||||
| ) | ) | ||||
| @@ -10,6 +10,8 @@ import ( | |||||
| "gitlink.org.cn/cloudream/common/utils/reflect2" | "gitlink.org.cn/cloudream/common/utils/reflect2" | ||||
| ) | ) | ||||
| var ErrCommandNotFound = fmt.Errorf("command not found") | |||||
| type ExecuteOption struct { | type ExecuteOption struct { | ||||
| ReplaceEmptyArrayWithNil bool // 如果最后一个参数是空数组,则调用命令的时候传递nil参数 | ReplaceEmptyArrayWithNil bool // 如果最后一个参数是空数组,则调用命令的时候传递nil参数 | ||||
| } | } | ||||
| @@ -178,7 +180,7 @@ func (t *anyCommandTrie) findCommand(cmdWords []string, argWords []string) (*com | |||||
| }) | }) | ||||
| if cmd == nil { | if cmd == nil { | ||||
| return nil, nil, fmt.Errorf("command not found") | |||||
| return nil, nil, ErrCommandNotFound | |||||
| } | } | ||||
| return cmd, argWords, nil | return cmd, argWords, nil | ||||
| } | } | ||||
| @@ -22,12 +22,12 @@ const ( | |||||
| var ErrWaitResponseTimeout = fmt.Errorf("wait response timeout") | var ErrWaitResponseTimeout = fmt.Errorf("wait response timeout") | ||||
| type CodeMessageError struct { | type CodeMessageError struct { | ||||
| code string | |||||
| message string | |||||
| Code string | |||||
| Message string | |||||
| } | } | ||||
| func (e *CodeMessageError) Error() 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 { | type SendOption struct { | ||||
| @@ -315,8 +315,8 @@ func Request[TSvc any, TReq MessageBody, TResp MessageBody](_ func(svc TSvc, msg | |||||
| errCode, errMsg := resp.GetCodeMessage() | errCode, errMsg := resp.GetCodeMessage() | ||||
| if errCode != errorcode.OK { | if errCode != errorcode.OK { | ||||
| return defRet, &CodeMessageError{ | return defRet, &CodeMessageError{ | ||||
| code: errCode, | |||||
| message: errMsg, | |||||
| Code: errCode, | |||||
| Message: errMsg, | |||||
| } | } | ||||
| } | } | ||||