app-cloudep-trade-service/internal/domain/errors.go

52 lines
1.1 KiB
Go
Raw Normal View History

2024-10-25 17:17:32 +00:00
package domain
import (
"strings"
ers "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"github.com/zeromicro/go-zero/core/logx"
)
type ErrorCode uint32
func (e ErrorCode) ToUint32() uint32 {
return uint32(e)
}
// Error Code 統一這邊改
const (
_ = iota
CreateOrderErrorCode ErrorCode = iota
CancelOrderErrorCode
ModifyOrderErrorCode
TimeoutOrderErrorCode
)
2024-10-29 14:49:47 +00:00
// Error Code 統一這邊改
const (
_ ErrorCode = 20 + iota
CreateWalletErrorCode
)
2024-10-25 17:17:32 +00:00
const (
_ ErrorCode = 10 + iota
DataNotFoundErrorCode
)
func CommentError(ec ErrorCode, s ...string) *ers.LibError {
return ers.NewError(code.CloudEPOrder, code.DBError, ec.ToUint32(), strings.Join(s, " "))
}
func CommentErrorL(ec ErrorCode,
l logx.Logger, filed []logx.LogField, s ...string) *ers.LibError {
e := CommentError(ec, s...)
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
return e
}
func NotFoundError(ec ErrorCode, s ...string) *ers.LibError {
return ers.NewError(code.CloudEPOrder, code.ResourceNotFound, ec.ToUint32(), strings.Join(s, " "))
}