Compare commits
0
Commits
master
..
255d79affb
No files matched your search
+1
-1
@@ -20,7 +20,7 @@ type IException interface {
|
||||
// Message 获取错误信息
|
||||
Message() string
|
||||
// Data 获取异常时的返回数据
|
||||
Data() any
|
||||
Data() map[string]any
|
||||
// ToError 转换为内置error类型
|
||||
ToError() error
|
||||
// IsCode 是否为指定code
|
||||
|
||||
@@ -102,12 +102,6 @@ func MessageWithoutCode() {
|
||||
//
|
||||
// Date : 21:16 2022/6/25
|
||||
func GetMessage(code any, defaultMessage ...string) string {
|
||||
if nil == code {
|
||||
return ""
|
||||
}
|
||||
if eCode, ok := code.(Code); ok {
|
||||
code = eCode.Value
|
||||
}
|
||||
var (
|
||||
inputCodeInfo Code
|
||||
exist bool
|
||||
|
||||
+5
-12
@@ -8,7 +8,6 @@
|
||||
package exception
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
@@ -24,18 +23,12 @@ import (
|
||||
type Exception struct {
|
||||
code any
|
||||
message string
|
||||
data any
|
||||
data map[string]any
|
||||
stack string
|
||||
}
|
||||
|
||||
func (e *Exception) Error() string {
|
||||
mapData := map[string]any{
|
||||
"code": e.Code(),
|
||||
"msg": e.Message(),
|
||||
"data": e.Data(),
|
||||
}
|
||||
byteData, _ := json.Marshal(mapData)
|
||||
return string(byteData)
|
||||
return e.Message()
|
||||
}
|
||||
|
||||
func (e *Exception) GetStack() string {
|
||||
@@ -50,7 +43,7 @@ func (e *Exception) Message() string {
|
||||
return e.message
|
||||
}
|
||||
|
||||
func (e *Exception) Data() any {
|
||||
func (e *Exception) Data() map[string]any {
|
||||
return e.data
|
||||
}
|
||||
|
||||
@@ -93,7 +86,7 @@ func NewWithCodeAndData(code any, data map[string]any) IException {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:28 2022/6/25
|
||||
func New(code any, data any, defaultMessage ...string) IException {
|
||||
func New(code any, data map[string]any, defaultMessage ...string) IException {
|
||||
if nil == data {
|
||||
// 保证数据结构的一致性, 同时避免后续使用出现空指针
|
||||
data = map[string]any{}
|
||||
@@ -164,6 +157,6 @@ func IsSuccess(e *Exception) bool {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 22:35 2022/6/25
|
||||
func NewSuccess(data any) IException {
|
||||
func NewSuccess(data map[string]any) IException {
|
||||
return New(defaultSuccessCode, data, "")
|
||||
}
|
||||