补充ErrorData

This commit is contained in:
wh_zcy 2023-05-31 18:31:44 +08:00
parent fa4b57748b
commit 283410f2e6
6 changed files with 40 additions and 43 deletions

View File

@ -20,16 +20,16 @@ func NewCustomError(code pb.ErrorCode) error {
// 初次调用得用Wrap方法进行实例化
return errors.Wrap(&CustomError{
Code: code,
Message: code.String(),
Message: code.ToString(),
}, "")
}
//创建配置表错误对象
// 创建配置表错误对象
func NewNotFoundConfErr(moduleName string, filename string, id interface{}) error {
return fmt.Errorf("服务端配置未找到!模块:%s ,配置文件:%s,目标数据:%v", moduleName, filename, id)
}
//执行外部模块异常
// 执行外部模块异常
func NewExternalModuleErr(moduleName string, methodname string, parameter ...interface{}) error {
return fmt.Errorf("执行外部模块错误 模块:%s ,配置文件:%s,目标数据:%v", moduleName, methodname, parameter)
}

View File

@ -50,6 +50,8 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.SociatyAgreeReq) (
} else {
code = pb.ErrorCode_DBError
}
data.Title = code.ToString()
data.Message = err.Error()
this.module.Error("公会审核-同意",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "申请人", Value: req.Uid},

View File

@ -40,15 +40,17 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (
userEx, err := this.module.ModuleUser.GetUserExpand(uid)
if err != nil {
this.module.Error("GetRemoteUserExpand", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
code = pb.ErrorCode_UserSessionNobeing
code = pb.ErrorCode_UserNofound
data.Title = code.ToString()
data.Datastring = uid
data.Message = err.Error()
return
}
if utils.IsInCDHour(userEx.SociatyCd) {
code = pb.ErrorCode_SociatyCDLimit
data.Title = code.ToString()
data.Message = fmt.Sprintf("CD内")
data.Message = fmt.Sprintf("CD内[%v]不允许申请", userEx.SociatyCd)
return
}
@ -56,30 +58,40 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (
if this.module.modelSociaty.isMember(uid, sociaty) {
code = pb.ErrorCode_SociatyBelongTo
data.Title = code.ToString()
data.Datastring = sociaty.Id
data.Message = fmt.Sprintf("[%v]已经是公会[%v]成员", uid, sociaty.Name)
return
}
user := this.module.ModuleUser.GetUser(uid)
if user == nil {
code = pb.ErrorCode_UserSessionNobeing
code = pb.ErrorCode_UserNofound
data.Title = code.ToString()
data.Datastring = uid
return
}
// 是否达到入会等级
if user.Lv < sociaty.ApplyLv {
code = pb.ErrorCode_SociatyAppyLvNoEnough
data.Title = code.ToString()
data.Message = fmt.Sprintf("实际等级:%v 期望等级:%v", user.Lv, sociaty.ApplyLv)
return
}
// 是否已申请
if this.module.modelSociaty.isApplied(uid, sociaty) {
code = pb.ErrorCode_SociatyApplied
data.Title = code.ToString()
data.Message = fmt.Sprintf("[%v]已申请", sociaty.Name)
return
}
//判断申请人数是否超出最大允许申请数
if len(sociaty.ApplyRecord) >= int(this.module.globalConf.GuildAcceptApplyMax) {
code = pb.ErrorCode_SociatyApplyMax
data.Title = code.ToString()
data.Message = fmt.Sprintf("实际人数:%d 期望人数:%d", len(sociaty.ApplyRecord), int(this.module.globalConf.GuildAcceptApplyMax))
return
}
@ -92,6 +104,8 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (
} else {
code = pb.ErrorCode_DBError
}
data.Title = code.ToString()
data.Message = err.Error()
this.module.Error("公会申请",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "sociatyId", Value: req.SociatyId},
@ -103,7 +117,6 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.SociatyApplyReq) (
// 无需审核
if !isCheck {
// 触发任务条件
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype109, 1)
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype109, 1))
}
rsp := &pb.SociatyApplyResp{

View File

@ -242,7 +242,7 @@ type TaskParams struct {
// 任务条件达成通知
func (this *Sociaty) TCondFinishNotify(uid string, condIds []int32) {
log.Debug("公会任务",
log.Debug("公会任务通知",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "condIds", Value: condIds})

View File

@ -99,10 +99,7 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
}
}
var (
condiFlag bool
)
var condiFlag bool
// 检查当前任务的完成条件
for _, condId := range curTaskConf.Completetask {
if v, ok := userTask.CurrentTask[req.GroupId]; ok {
@ -112,7 +109,12 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
if err == nil && len(conIds) > 0 {
condiFlag = true
} else {
condiFlag = false
code = pb.ErrorCode_ExternalModule
data = &pb.ErrorData{
Title: code.ToString(),
Message: comm.NewExternalModuleErr("Buried", "CheckCondition", uid, condId).Error(),
}
return
}
} else {
condiFlag = true
@ -162,18 +164,15 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
return
}
func (this *apiComp) updateCheckCond(uid string, userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
func (this *apiComp) updateCheckCond(uid string, userTask *pb.DBWorldtask, nextTaskId int32) (*pb.DBWorldtask, error) {
//检查下个任务的完成条件
nextTaskConf, err := this.module.configure.getWorldtaskById(nextTaskId)
if err != nil {
this.module.Error("config not found", log.Field{Key: "taskId", Value: nextTaskId})
return nil
}
if nextTaskConf == nil {
return nil
return nil, err
}
if nextTaskConf.Des == 1 || nextTaskConf.Des == 4 {
return nil
return nil, comm.NewCustomError(pb.ErrorCode_WorldtaskNoProcess)
}
if userTask.CurrentTask == nil {
@ -219,9 +218,9 @@ func (this *apiComp) updateCheckCond(uid string, userTask *pb.DBWorldtask, nextT
if len(update) > 0 {
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
this.module.Error("DB err", log.Field{Key: "err", Value: err.Error()})
return nil
return nil, err
}
}
return userTask
return userTask, nil
}

View File

@ -161,7 +161,8 @@ func (this *ModelWorldtask) checkCondi(uid string, condiId int32) bool {
return false
}
func (this *ModelWorldtask) updateCheckCond(uid string, userLv int32, userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
// 更新当前任务的完成条件
func (this *ModelWorldtask) updateCurrentTaskCond(uid string, userLv int32, userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
//检查下个任务的完成条件
nextTaskConf, err := this.moduleWorldtask.configure.getWorldtaskById(nextTaskId)
if err != nil {
@ -208,25 +209,7 @@ func (this *ModelWorldtask) updateCheckCond(uid string, userLv int32, userTask *
TaskType: nextTaskConf.Des,
}
}
// if m, err := this.service.GetModule(comm.ModuleRtask); err == nil {
// iwt, ok := m.(comm.IRtask)
// if ok {
// if mc := iwt.CheckCondi(uid, condiId); mc != pb.ErrorCode_Success {
// this.moduleWorldtask.Debug("任务完成条件不满足",
// log.Field{Key: "uid", Value: uid},
// log.Field{Key: "taskId", Value: nextTaskId},
// log.Field{Key: "condiId", Value: condiId},
// )
// } else {
// if ok {
// nwt.CondiIds = append(nwt.CondiIds, condiId)
// } else {
// condiIds := []int32{condiId}
// nwt.CondiIds = condiIds
// }
// }
// }
// }
condIds, _, err := this.moduleWorldtask.ModuleBuried.CheckCondition(uid, condiId)
if err == nil && len(condIds) > 0 {
nwt.CondiIds = condIds
@ -261,7 +244,7 @@ func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, groupId in
nextTask := make(map[int32]*pb.Worldtask)
for _, next := range nextTaskIds {
ut := this.updateCheckCond(session.GetUserId(), u.Lv, userTask, next)
ut := this.updateCurrentTaskCond(session.GetUserId(), u.Lv, userTask, next)
if ut != nil {
for k, v := range ut.CurrentTask {
nextTask[k] = &pb.Worldtask{