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

39 lines
874 B
Go

package domain
import (
"code.30cm.net/digimon/library-go/errs"
"code.30cm.net/digimon/library-go/errs/code"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"strings"
)
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
}