解决自定义异常消息无法透出问题

解决自定义异常消息无法透出问题
This commit is contained in:
2023-08-19 10:42:37 +08:00
parent 16920b714d
commit f674702ad2
2 changed files with 14 additions and 11 deletions

11
code.go
View File

@@ -102,9 +102,12 @@ func MessageWithoutCode() {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:16 2022/6/25
func getMessage(code interface{}) string {
func getMessage(code interface{}, defaultMessage ...string) string {
inputCodeInfo, exist := codeTable[code]
if !exist {
if len(defaultMessage) > 0 && len(defaultMessage[0]) > 0 {
return defaultMessage[0]
}
// 无论是否开启 messageWithCode , 未知错误强行带 code
return fmt.Sprintf("未知错误【%v】", code)
}
@@ -123,8 +126,8 @@ func getMessage(code interface{}) string {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 12:58 2022/6/26
func GetMessage(code interface{}) string {
return getMessage(code)
func GetMessage(code interface{}, defaultMessage ...string) string {
return getMessage(code, defaultMessage...)
}
// GetCodeList ...
@@ -153,7 +156,7 @@ func GetCodeTable() map[interface{}]Code {
func getReason(code interface{}) string {
inputCodeInfo, exist := codeTable[code]
if !exist {
return getMessage(code)
return getMessage(code, "")
}
return inputCodeInfo.Reason[defaultLanguage]
}