fix(notify): per-recipient timeout and return user on email removal
- Use per-recipient context timeout in sendEmails to prevent later recipients from failing due to shared timeout exhaustion - Return updated user object from RemoveNotifyEmail handler for frontend state consistency (matching VerifyNotifyEmail pattern)
This commit is contained in:
@@ -205,5 +205,12 @@ func (h *UserHandler) RemoveNotifyEmail(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, gin.H{"message": "Email removed successfully"})
|
// Return updated user
|
||||||
|
updatedUser, err := h.userService.GetByID(c.Request.Context(), subject.UserID)
|
||||||
|
if err != nil {
|
||||||
|
response.ErrorFrom(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, dto.UserFromService(updatedUser))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,13 +186,13 @@ func (s *BalanceNotifyService) collectBalanceNotifyRecipients(user *User) []stri
|
|||||||
|
|
||||||
// sendEmails sends an email to all recipients with shared timeout and error logging.
|
// sendEmails sends an email to all recipients with shared timeout and error logging.
|
||||||
func (s *BalanceNotifyService) sendEmails(recipients []string, subject, body string, logAttrs ...any) {
|
func (s *BalanceNotifyService) sendEmails(recipients []string, subject, body string, logAttrs ...any) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), emailSendTimeout)
|
|
||||||
defer cancel()
|
|
||||||
for _, to := range recipients {
|
for _, to := range recipients {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), emailSendTimeout)
|
||||||
if err := s.emailService.SendEmail(ctx, to, subject, body); err != nil {
|
if err := s.emailService.SendEmail(ctx, to, subject, body); err != nil {
|
||||||
attrs := append([]any{"to", to, "error", err}, logAttrs...)
|
attrs := append([]any{"to", to, "error", err}, logAttrs...)
|
||||||
slog.Error("failed to send notification", attrs...)
|
slog.Error("failed to send notification", attrs...)
|
||||||
}
|
}
|
||||||
|
cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user