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

49 lines
974 B
Go
Raw Normal View History

2024-08-30 02:44:35 +00:00
package domain
2024-08-30 06:30:39 +00:00
import (
2024-08-30 07:00:23 +00:00
"fmt"
"strings"
2024-08-30 06:30:39 +00:00
ers "code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"github.com/zeromicro/go-zero/core/logx"
)
2024-08-30 02:44:35 +00:00
type ErrorCode uint32
func (e ErrorCode) ToUint32() uint32 {
return uint32(e)
}
// Error Code 統一這邊改
const (
_ = iota
PostMongoErrorCode ErrorCode = iota
CreatePostError
DelPostError
UpdatePostError
ListPostError
)
2024-08-30 06:30:39 +00:00
const (
CommentFoundErrorCode ErrorCode = iota + 10
CommentInsertErrorCode
CommentDeleteErrorCode
CommentUpdateErrorCode
CommentListErrorCode
)
func CommentError(ec ErrorCode, s ...string) *ers.LibError {
return ers.NewError(code.CloudEPTweeting, code.DBError,
ec.ToUint32(),
fmt.Sprintf("%s", 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
}