2024-06-07 11:11:04 +08:00
|
|
|
|
package xerr
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
2024-06-12 13:46:14 +08:00
|
|
|
|
"trasfer_middleware/until/sysLog"
|
2024-06-07 11:11:04 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
常用通用固定错误
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
type CodeError struct {
|
|
|
|
|
errCode uint32
|
|
|
|
|
errMsg string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回给前端的错误码
|
|
|
|
|
func (e *CodeError) GetErrCode() uint32 {
|
|
|
|
|
return e.errCode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回给前端显示端错误信息
|
|
|
|
|
func (e *CodeError) GetErrMsg() string {
|
|
|
|
|
return e.errMsg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *CodeError) Error() string {
|
|
|
|
|
return fmt.Sprintf("ErrCode:%d,ErrMsg:%s", e.errCode, e.errMsg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewErrCodeMsg(errCode uint32, errMsg string) *CodeError {
|
|
|
|
|
return &CodeError{errCode: errCode, errMsg: errMsg}
|
|
|
|
|
}
|
|
|
|
|
func NewErrCode(errCode uint32) *CodeError {
|
|
|
|
|
return &CodeError{errCode: errCode, errMsg: MapErrMsg(errCode)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewErrMsg(ctx context.Context, errMsg string) *CodeError {
|
2024-06-12 13:46:14 +08:00
|
|
|
|
sysLog.ErrLog(ctx, errMsg)
|
2024-06-07 11:11:04 +08:00
|
|
|
|
return &CodeError{errCode: SERVER_COMMON_ERROR, errMsg: errMsg}
|
|
|
|
|
}
|