解决自定义异常消息无法透出问题
解决自定义异常消息无法透出问题
This commit is contained in:
14
exception.go
14
exception.go
@ -65,7 +65,7 @@ func (e *Exception) ToError() error {
|
||||
//
|
||||
// Date : 21:22 2022/6/25
|
||||
func NewWithCode(code interface{}) IException {
|
||||
return New(code, defaultHttpCode, nil)
|
||||
return New(code, defaultHttpCode, nil, "")
|
||||
}
|
||||
|
||||
// NewWithCodeAndHttpCode 使用 code + http_code 获取实例
|
||||
@ -74,7 +74,7 @@ func NewWithCode(code interface{}) IException {
|
||||
//
|
||||
// Date : 21:25 2022/6/25
|
||||
func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException {
|
||||
return New(code, httpCode, nil)
|
||||
return New(code, httpCode, nil, "")
|
||||
}
|
||||
|
||||
// NewWithCodeAndData 使用 code + data 获取异常实例
|
||||
@ -83,7 +83,7 @@ func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException {
|
||||
//
|
||||
// Date : 21:28 2022/6/25
|
||||
func NewWithCodeAndData(code interface{}, data interface{}) IException {
|
||||
return New(code, defaultHttpCode, data)
|
||||
return New(code, defaultHttpCode, data, "")
|
||||
}
|
||||
|
||||
// New 获取异常实例
|
||||
@ -91,14 +91,14 @@ func NewWithCodeAndData(code interface{}, data interface{}) IException {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:28 2022/6/25
|
||||
func New(code interface{}, httpCode int, data interface{}) IException {
|
||||
func New(code interface{}, httpCode int, data interface{}, defaultMessage ...string) IException {
|
||||
if nil == data {
|
||||
// 保证数据结构的一致性, 同时避免后续使用出现空指针
|
||||
data = map[string]interface{}{}
|
||||
}
|
||||
return &Exception{
|
||||
code: code,
|
||||
message: getMessage(code),
|
||||
message: getMessage(code, defaultMessage...),
|
||||
httpCode: httpCode,
|
||||
data: data,
|
||||
}
|
||||
@ -115,7 +115,7 @@ func NewFromError(code interface{}, err error) IException {
|
||||
}
|
||||
return New(code, defaultHttpCode, map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
}, err.Error())
|
||||
}
|
||||
|
||||
// NewFromMessage 从 code message 生成exception
|
||||
@ -157,5 +157,5 @@ func IsSuccess(e *Exception) bool {
|
||||
//
|
||||
// Date : 22:35 2022/6/25
|
||||
func NewSuccess(data interface{}) IException {
|
||||
return New(defaultSuccessCode, defaultHttpCode, data)
|
||||
return New(defaultSuccessCode, defaultHttpCode, data, "")
|
||||
}
|
||||
|
Reference in New Issue
Block a user