From bf1de24bcd9f2a108676a4ecdb2d81d20e7a20ff Mon Sep 17 00:00:00 2001 From: Leufolium Date: Mon, 22 Apr 2024 18:33:40 +0800 Subject: [PATCH] by Robin at 20240422 --- api/errcode/errcode.go | 4 ++++ app/mix/service/apiservice.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index ed14a5f7..c23b5fc0 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -192,11 +192,13 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeZoneThirdPartnerSrvFail: "空间代运营表服务错误", ErrCodeZoneThirdPartnerNotExist: "空间代运营表不存在", ErrCodeZoneThirdPartnerWrongThirdPartner: "空间代运营不能设置成自己", + ErrCodeZoneThirdPartnerDuplicateKey: "空间代运营已设置,请勿重复设置代运营!", ErrCodeZoneCollaboratorSrvFail: "空间协作者表服务错误", ErrCodeZoneCollaboratorNotExist: "空间协作者表不存在", ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation: "空间协作者表创建操作只有空间代运营可操作", ErrCodeZoneCollaboratorWrongCollaborator: "空间协作者不能设置成自己或者主播", + ErrCodeZoneCollaboratorDuplicateKey: "用户已是该空间协作者!", ErrCodeZoneMomentCreateTimesSrvFail: "空间动态创建频次表服务错误", ErrCodeZoneMomentCreateTimesNotExist: "空间动态创建频次表不存在", @@ -468,6 +470,7 @@ const ( ErrCodeZoneThirdPartnerSrvFail ErrCode = -37001 // 空间代运营表服务错误 ErrCodeZoneThirdPartnerNotExist ErrCode = -37002 // 空间代运营表不存在 ErrCodeZoneThirdPartnerWrongThirdPartner ErrCode = -37003 // 空间代运营不能设置成自己 + ErrCodeZoneThirdPartnerDuplicateKey ErrCode = -37004 // 空间代运营重复创建 // ZoneCollaborator: 38xxx ErrCodeZoneCollaboratorSrvOk ErrCode = ErrCodeOk @@ -475,6 +478,7 @@ const ( ErrCodeZoneCollaboratorNotExist ErrCode = -38002 // 空间协作者表不存在 ErrCodeZoneCollaboratorCreateIsZTPOnlyOperation ErrCode = -38003 // 空间协作者表创建操作只有空间代运营可操作 ErrCodeZoneCollaboratorWrongCollaborator ErrCode = -38004 // 空间协作者不能设置成自己或者主播 + ErrCodeZoneCollaboratorDuplicateKey ErrCode = -38005 // 空间协作者重复创建 // MomentCreateTimes: 39xxx ErrCodeZoneMomentCreateTimesSrvOk ErrCode = ErrCodeOk diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 21925810..740b05f7 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2908,6 +2908,11 @@ func (s *Service) ApiCreateZoneThirdPartner(ctx *gin.Context, req *zone_third_pa BaseRequest: req.BaseRequest, ZoneThirdPartner: req.ZoneThirdPartner, }) + if mongo.IsDuplicateKeyError(err) { + logger.Error("ApiCreate duplicate key found, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneThirdPartnerDuplicateKey + return + } if err != nil { logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneThirdPartnerSrvFail @@ -2996,6 +3001,11 @@ func (s *Service) ApiCreateZoneCollaborator(ctx *gin.Context, req *zone_collabor BaseRequest: req.BaseRequest, ZoneCollaborator: req.ZoneCollaborator, }) + if mongo.IsDuplicateKeyError(err) { + logger.Error("ApiCreate duplicate key found, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneCollaboratorDuplicateKey + return + } if err != nil { logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeZoneCollaboratorSrvFail