fix: 更新短信发送错误处理,返回详细错误信息以便调试,改善用户体验
This commit is contained in:
1 parent
7062b9f1e8
commit
19a80887b3
2 files changed
+8
-10
No files matched your search
@@ -442,10 +442,9 @@ func (s *cuUserService) sendSmsCode(ctx context.Context, phone, phoneCountryCode
|
||||
switch sendErr {
|
||||
case utils.ErrSMSRateLimited:
|
||||
return i18n.NewI18nError("500016", lang) // 短信发送过于频繁,请稍后再试
|
||||
case utils.ErrSMSSendFailed:
|
||||
return i18n.NewI18nError("500017", lang) // 短信发送失败
|
||||
default:
|
||||
return i18n.NewI18nError("200004", lang) // 短信发送失败
|
||||
// 对于短信发送失败,结合本地化消息和具体错误信息,便于调试
|
||||
return i18n.NewI18nError("500017", lang, sendErr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,10 +495,9 @@ func (s *cuUserService) SendCurrentPhoneSms(ctx context.Context, userID string)
|
||||
switch err {
|
||||
case utils.ErrSMSRateLimited:
|
||||
return i18n.NewI18nError("500016", lang) // 短信发送过于频繁,请稍后再试
|
||||
case utils.ErrSMSSendFailed:
|
||||
return i18n.NewI18nError("500017", lang) // 短信发送失败
|
||||
default:
|
||||
return i18n.NewI18nError("200004", lang) // 短信发送失败
|
||||
// 对于短信发送失败,结合本地化消息和具体错误信息,便于调试
|
||||
return i18n.NewI18nError("500017", lang, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,10 +533,9 @@ func (s *cuUserService) SendNewPhoneSms(ctx context.Context, req *models.CuUserS
|
||||
switch err {
|
||||
case utils.ErrSMSRateLimited:
|
||||
return i18n.NewI18nError("500016", lang) // 短信发送过于频繁,请稍后再试
|
||||
case utils.ErrSMSSendFailed:
|
||||
return i18n.NewI18nError("500017", lang) // 短信发送失败
|
||||
default:
|
||||
return i18n.NewI18nError("200004", lang) // 短信发送失败
|
||||
// 对于短信发送失败,结合本地化消息和具体错误信息,便于调试
|
||||
return i18n.NewI18nError("500017", lang, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ func (s *smsService) SendVerificationCode(ctx context.Context, phone, phoneCount
|
||||
err := s.sendSMS(fullPhone, templateCode, code)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to send SMS to %s: %v", fullPhone, err)
|
||||
return ErrSMSSendFailed
|
||||
// 返回包含详细错误信息的错误,这样上层可以获取具体错误原因
|
||||
return fmt.Errorf("SMS send failed: %w", err)
|
||||
}
|
||||
|
||||
// 缓存验证码
|
||||
|
||||
Reference in new issue
Block a user