Migrating AppError to error for mailservice (#16810)
* Migrating AppError to error for mailservice * Updating i18n strings * Fixing shadow variable problem * Addressing PR review comments * fixing test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
572f861675
Коммит
fbe0294e86
34
app/email.go
34
app/email.go
@@ -292,7 +292,7 @@ func (es *EmailService) SendPasswordResetEmail(email string, token *model.Token,
|
||||
bodyPage.Props["Button"] = T("api.templates.reset_body.button")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendPasswordReset", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendPasswordReset", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -462,8 +462,8 @@ func (es *EmailService) sendGuestInviteEmails(team *model.Team, channels []*mode
|
||||
}
|
||||
}
|
||||
|
||||
if err := es.sendMailWithEmbeddedFiles(invite, subject, bodyPage.Render(), embeddedFiles); err != nil {
|
||||
mlog.Error("Failed to send invite email successfully", mlog.Err(err))
|
||||
if nErr := es.sendMailWithEmbeddedFiles(invite, subject, bodyPage.Render(), embeddedFiles); nErr != nil {
|
||||
mlog.Error("Failed to send invite email successfully", mlog.Err(nErr))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,23 +545,23 @@ func (es *EmailService) SendRemoveExpiredLicenseEmail(email string, locale, site
|
||||
return nil
|
||||
}
|
||||
|
||||
func (es *EmailService) sendNotificationMail(to, subject, htmlBody string) *model.AppError {
|
||||
func (es *EmailService) sendNotificationMail(to, subject, htmlBody string) error {
|
||||
if !*es.srv.Config().EmailSettings.SendEmailNotifications {
|
||||
return nil
|
||||
}
|
||||
return es.sendMail(to, subject, htmlBody)
|
||||
}
|
||||
|
||||
func (es *EmailService) sendMail(to, subject, htmlBody string) *model.AppError {
|
||||
func (es *EmailService) sendMail(to, subject, htmlBody string) error {
|
||||
return es.sendMailWithCC(to, subject, htmlBody, "")
|
||||
}
|
||||
|
||||
func (es *EmailService) sendMailWithCC(to, subject, htmlBody string, ccMail string) *model.AppError {
|
||||
func (es *EmailService) sendMailWithCC(to, subject, htmlBody string, ccMail string) error {
|
||||
license := es.srv.License()
|
||||
return mailservice.SendMailUsingConfig(to, subject, htmlBody, es.srv.Config(), license != nil && *license.Features.Compliance, ccMail)
|
||||
}
|
||||
|
||||
func (es *EmailService) sendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) *model.AppError {
|
||||
func (es *EmailService) sendMailWithEmbeddedFiles(to, subject, htmlBody string, embeddedFiles map[string]io.Reader) error {
|
||||
license := es.srv.License()
|
||||
config := es.srv.Config()
|
||||
|
||||
@@ -613,7 +613,7 @@ func (es *EmailService) SendAtUserLimitWarningEmail(email string, locale string,
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendAtUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendAtUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -635,7 +635,7 @@ func (es *EmailService) SendOverUserLimitWarningEmail(email string, locale strin
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -660,7 +660,7 @@ func (es *EmailService) SendOverUserLimitThirtyDayWarningEmail(email string, loc
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -684,7 +684,7 @@ func (es *EmailService) SendOverUserLimitNinetyDayWarningEmail(email string, loc
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -706,7 +706,7 @@ func (es *EmailService) SendOverUserLimitWorkspaceSuspendedWarningEmail(email st
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -727,7 +727,7 @@ func (es *EmailService) SendOverUserFourteenDayWarningEmail(email string, locale
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -748,7 +748,7 @@ func (es *EmailService) SendOverUserSevenDayWarningEmail(email string, locale st
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -767,7 +767,7 @@ func (es *EmailService) SendSuspensionEmailToSupport(email string, installationI
|
||||
bodyPage.Props["UserCount"] = userCount
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendOverUserLimitWarningEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -792,7 +792,7 @@ func (es *EmailService) SendPaymentFailedEmail(email string, locale string, fail
|
||||
bodyPage.Props["FailedReason"] = failedPayment.FailureMessage
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return false, model.NewAppError("SendPaymentFailedEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return false, model.NewAppError("SendPaymentFailedEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
@@ -814,7 +814,7 @@ func (es *EmailService) SendNoCardPaymentFailedEmail(email string, locale string
|
||||
bodyPage.Props["Footer"] = T("api.templates.copyright")
|
||||
|
||||
if err := es.sendMail(email, subject, bodyPage.Render()); err != nil {
|
||||
return model.NewAppError("SendPaymentFailedEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return model.NewAppError("SendPaymentFailedEmail", "api.user.send_password_reset.send.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -239,8 +239,8 @@ func (es *EmailService) sendBatchedEmailNotification(userID string, notification
|
||||
body.Props["Posts"] = template.HTML(contents)
|
||||
body.Props["BodyText"] = translateFunc("api.email_batching.send_batched_email_notification.body_text", len(notifications))
|
||||
|
||||
if err := es.sendNotificationMail(user.Email, subject, body.Render()); err != nil {
|
||||
mlog.Warn("Unable to send batched email notification", mlog.String("email", user.Email), mlog.Err(err))
|
||||
if nErr := es.sendNotificationMail(user.Email, subject, body.Render()); nErr != nil {
|
||||
mlog.Warn("Unable to send batched email notification", mlog.String("email", user.Email), mlog.Err(nErr))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ func (a *App) sendNotificationEmail(notification *PostNotification, user *model.
|
||||
var bodyText = a.getNotificationEmailBody(user, post, channel, channelName, senderName, team.Name, landingURL, emailNotificationContentsType, useMilitaryTime, translateFunc)
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.sendNotificationMail(user.Email, html.UnescapeString(subjectText), bodyText); err != nil {
|
||||
mlog.Error("Error while sending the email", mlog.String("user_email", user.Email), mlog.Err(err))
|
||||
if nErr := a.Srv().EmailService.sendNotificationMail(user.Email, html.UnescapeString(subjectText), bodyText); nErr != nil {
|
||||
mlog.Error("Error while sending the email", mlog.String("user_email", user.Email), mlog.Err(nErr))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -731,7 +731,11 @@ func (api *PluginAPI) SendMail(to, subject, htmlBody string) *model.AppError {
|
||||
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
return api.app.Srv().EmailService.sendNotificationMail(to, subject, htmlBody)
|
||||
if err := api.app.Srv().EmailService.sendNotificationMail(to, subject, htmlBody); err != nil {
|
||||
return model.NewAppError("SendMail", "plugin_api.send_mail.missing_htmlbody", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Plugin Section
|
||||
|
||||
@@ -473,8 +473,8 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
}
|
||||
s.WebSocketRouter.app = fakeApp
|
||||
|
||||
if appErr := mailservice.TestConnection(s.Config()); appErr != nil {
|
||||
mlog.Error("Mail server connection test is failed: " + appErr.Message)
|
||||
if nErr := mailservice.TestConnection(s.Config()); nErr != nil {
|
||||
mlog.Error("Mail server connection test is failed", mlog.Err(nErr))
|
||||
}
|
||||
|
||||
if _, err = url.ParseRequestURI(*s.Config().ServiceSettings.SiteURL); err != nil {
|
||||
@@ -485,8 +485,7 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
if appErr != nil {
|
||||
mlog.Error("Problem with file storage settings", mlog.Err(appErr))
|
||||
} else {
|
||||
nErr := backend.TestConnection()
|
||||
if nErr != nil {
|
||||
if nErr := backend.TestConnection(); nErr != nil {
|
||||
mlog.Error("Problem with file storage settings", mlog.Err(nErr))
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user