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

40 lines
875 B
Go
Raw Permalink Normal View History

2024-08-29 01:08:15 +00:00
package domain
import (
2024-08-29 14:50:09 +00:00
"fmt"
"strings"
2024-08-29 01:08:15 +00:00
"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)
}
const (
_ = iota
PostMongoErrorCode ErrorCode = iota
)
// PostMongoError ...
func PostMongoError(s ...string) *errs.LibError {
return errs.NewError(code.CloudEPTweeting, code.DBError,
PostMongoErrorCode.ToUint32(),
fmt.Sprintf("%s", strings.Join(s, " ")))
}
// PostMongoErrorL logs error message and returns Err
func PostMongoErrorL(l logx.Logger, filed []logx.LogField, s ...string) *errs.LibError {
e := PostMongoError(s...)
if filed != nil || len(filed) >= 0 {
l.WithCallerSkip(1).WithFields(filed...).Error(e.Error())
}
l.WithCallerSkip(1).Error(e.Error())
return e
}