From 1ddfbad7dab05aa0ecb29fbff6720826104c0e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 11 Feb 2023 22:29:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=AE=9E=E4=BE=8B=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 45 +++++---------------------------------------- exception.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84ecd7c..429c340 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - true \ No newline at end of file diff --git a/exception.go b/exception.go index aa4a8b1..5274b18 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 异常接口的具体实现 // @@ -100,6 +103,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<白茶清欢> From e81729324c1ee5e6c2ecb699424998fe9fbd75e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 11 Feb 2023 23:35:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E6=9C=AA=E6=B3=A8=E5=86=8C=E6=97=B6,=20message?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 22 +++++++++++++++++++--- code.go | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 429c340..beb1148 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,7 +5,7 @@ - + - + @@ -34,6 +34,9 @@ + + @@ -59,4 +71,8 @@ + + false + 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 {