From 5ab4cc9e7fa70175a4be6d209ac49263c441baf9 Mon Sep 17 00:00:00 2001 From: rainzm Date: Tue, 6 Jul 2021 16:07:26 +0800 Subject: [PATCH] fix(notify): set default lang 'zh_CN' for robot --- pkg/notify/models/robot.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/notify/models/robot.go b/pkg/notify/models/robot.go index 00afeb6148..788cf1b198 100644 --- a/pkg/notify/models/robot.go +++ b/pkg/notify/models/robot.go @@ -159,9 +159,13 @@ func (rm *SRobotManager) ValidateCreateData(ctx context.Context, userCred mcclie return input, httperrors.NewInputParameterError("unkown type %q", input.Type) } // check lang - _, err = language.Parse(input.Lang) - if err != nil { - return input, httperrors.NewInputParameterError("invalid lang %q: %s", input.Lang, err.Error()) + if input.Lang == "" { + input.Lang = "zh_CN" + } else { + _, err = language.Parse(input.Lang) + if err != nil { + return input, httperrors.NewInputParameterError("invalid lang %q: %s", input.Lang, err.Error()) + } } // check Address records, err := NotifyService.SendRobotMessage(ctx, input.Type, []*rpcapi.SReceiver{ @@ -220,9 +224,13 @@ func (r *SRobot) ValidateUpdateData(ctx context.Context, userCred mcclient.Token return input, errors.Wrap(err, "SSharableVirtualResourceBase.ValidateUpdateData") } // check lang - _, err = language.Parse(input.Lang) - if err != nil { - return input, httperrors.NewInputParameterError("invalid lang %q: %s", input.Lang, err.Error()) + if input.Lang == "" { + input.Lang = "zh_CN" + } else { + _, err = language.Parse(input.Lang) + if err != nil { + return input, httperrors.NewInputParameterError("invalid lang %q: %s", input.Lang, err.Error()) + } } // check Address records, err := NotifyService.SendRobotMessage(ctx, r.Type, []*rpcapi.SReceiver{