From 6e95e21e9878b6f8f91ffdec1aa409e0d54ebe48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Mon, 8 Jul 2024 21:31:11 +0800 Subject: [PATCH] fix(notify): avoid panic when mobile not set (#20744) --- pkg/notify/sender/mobile.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/notify/sender/mobile.go b/pkg/notify/sender/mobile.go index abed79868a..88961f8c73 100644 --- a/pkg/notify/sender/mobile.go +++ b/pkg/notify/sender/mobile.go @@ -40,11 +40,18 @@ func (smsSender *SMobileSender) Send(ctx context.Context, args api.SendParams) e RemoteTemplate: args.RemoteTemplate, RemoteTemplateParam: args.RemoteTemplateParam, } - smsdriver := models.GetSMSDriver(models.ConfigMap[api.MOBILE].Content.SmsDriver) + config, ok := models.ConfigMap[api.MOBILE] + if !ok { + return errors.Wrapf(errors.ErrNotFound, "no set %s config", api.MOBILE) + } + if config.Content == nil { + return errors.Wrapf(errors.ErrNotFound, "no %s content found", api.MOBILE) + } + smsdriver := models.GetSMSDriver(config.Content.SmsDriver) return smsdriver.Send(smsSendParams, false, &api.NotifyConfig{ - SNotifyConfigContent: *models.ConfigMap[api.MOBILE].Content, - Attribution: models.ConfigMap[api.MOBILE].Attribution, - DomainId: models.ConfigMap[api.MOBILE].DomainId, + SNotifyConfigContent: *config.Content, + Attribution: config.Attribution, + DomainId: config.DomainId, }) }