diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index ed3c81b..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - \ No newline at end of file diff --git a/code.go b/code.go index 65e416d..338ce29 100644 --- a/code.go +++ b/code.go @@ -72,7 +72,7 @@ func getMessage(code interface{}) string { message, exist := codeTable[code] if !exist { // 无论是否开启 messageWithCode , 未知错误强行带 code - return fmt.Sprintf("未知错误【%v】", codeTable) + return fmt.Sprintf("未知错误【%v】", code) } if messageWithCode { if code == defaultSuccessCode { diff --git a/exception.go b/exception.go index 85ddd71..cb45a4f 100644 --- a/exception.go +++ b/exception.go @@ -7,7 +7,10 @@ // Date *: 2022-06-25 21:04 package exception -import "errors" +import ( + "errors" + "fmt" +) // Exception 异常接口的具体实现 // @@ -107,6 +110,18 @@ func NewFromError(code interface{}, err error) IException { }) } +// NewFromMessage 从 code message 生成exception +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 22:25 2023/2/11 +func NewFromMessage(code interface{}, message string) IException { + if len(message) == 0 { + message = fmt.Sprintf("%v", code) + } + return NewFromError(code, errors.New(message)) +} + // ToError 转换成内置error // // Author : go_developer@163.com<白茶清欢>