Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server] Log errors from Listmonk

vishnukvmdb5edba4b4017
diff --git a/server/pkg/controller/mailing_lists.go b/server/pkg/controller/mailing_lists.go
index 497d00a69e..7d2761603a 100644
--- a/server/pkg/controller/mailing_lists.go
+++ b/server/pkg/controller/mailing_lists.go
@@ -212,8 +212,12 @@ func (c *MailingListsController) listmonkSubscribe(email string) error {
"email": email,
"lists": c.listmonkListIDs,
}
- return listmonk.SendRequest("POST", c.listmonkCredentials.BaseURL+"/api/subscribers", data,
+ err := listmonk.SendRequest("POST", c.listmonkCredentials.BaseURL+"/api/subscribers", data,
c.listmonkCredentials.Username, c.listmonkCredentials.Password)
+ if err != nil {
+ log.Errorf("Listmonk - Could not subscribe '%s': %s", email, err)
+ }
+ return err
}
// Unsubscribes an email address to a particular listmonk campaign mailing list
@@ -226,9 +230,14 @@ func (c *MailingListsController) listmonkUnsubscribe(email string) error {
id, err := listmonk.GetSubscriberID(c.listmonkCredentials.BaseURL+"/api/subscribers",
c.listmonkCredentials.Username, c.listmonkCredentials.Password, email)
if err != nil {
- stacktrace.Propagate(err, "")
+ log.Errorf("Listmonk - Could not find subscriber '%s': %s", email, err)
+ return stacktrace.Propagate(err, "")
}
- return listmonk.SendRequest("DELETE", c.listmonkCredentials.BaseURL+"/api/subscribers/"+strconv.Itoa(id),
+ err = listmonk.SendRequest("DELETE", c.listmonkCredentials.BaseURL+"/api/subscribers/"+strconv.Itoa(id),
map[string]interface{}{}, c.listmonkCredentials.Username, c.listmonkCredentials.Password)
+ if err != nil {
+ log.Errorf("Listmonk - Could not unsubscribe '%s': %s", email, err)
+ }
+ return err
}
diff --git a/server/pkg/controller/user/user.go b/server/pkg/controller/user/user.go
index 048eaa54df..82a222afe6 100644
--- a/server/pkg/controller/user/user.go
+++ b/server/pkg/controller/user/user.go
@@ -267,7 +267,13 @@ func (c *UserController) HandleAccountDeletion(ctx *gin.Context, userID int64, l
email := user.Email
// See also: Do not block on mailing list errors
go func() {
- _ = c.MailingListsController.Unsubscribe(email)
+ if err := c.MailingListsController.Unsubscribe(email); err != nil {
+ logrus.WithError(err).WithFields(logrus.Fields{
+ "req_id": ctx.GetString("req_id"),
+ "user_id": userID,
+ "email": email,
+ }).Error("mailing list unsubscribe failed")
+ }
}()
logger.Info("mark user as deleted")
@@ -426,7 +432,12 @@ func (c *UserController) createUser(email string, source *string) (int64, ente.S
// perform these actions async, and ignore errors that happen with them (a
// notification will be sent to Discord for those).
go func() {
- _ = c.MailingListsController.Subscribe(email)
+ if err := c.MailingListsController.Subscribe(email); err != nil {
+ logrus.WithError(err).WithFields(logrus.Fields{
+ "user_id": userID,
+ "email": email,
+ }).Error("mailing list subscribe failed")
+ }
}()
return userID, subscription, nil
}
diff --git a/server/pkg/controller/user/userauth.go b/server/pkg/controller/user/userauth.go
index fc45199110..af2dd4e74b 100644
--- a/server/pkg/controller/user/userauth.go
+++ b/server/pkg/controller/user/userauth.go
@@ -330,8 +330,20 @@ func (c *UserController) UpdateEmail(ctx *gin.Context, userID int64, email strin
//
// See also: Do not block on mailing list errors
go func() {
- _ = c.MailingListsController.Unsubscribe(oldEmail)
- _ = c.MailingListsController.Subscribe(email)
+ if err := c.MailingListsController.Unsubscribe(oldEmail); err != nil {
+ log.WithError(err).WithFields(log.Fields{
+ "req_id": requestid.Get(ctx),
+ "user_id": userID,
+ "email": oldEmail,
+ }).Error("mailing list unsubscribe failed")
+ }
+ if err := c.MailingListsController.Subscribe(email); err != nil {
+ log.WithError(err).WithFields(log.Fields{
+ "req_id": requestid.Get(ctx),
+ "user_id": userID,
+ "email": email,
+ }).Error("mailing list subscribe failed")
+ }
}()
return nil
diff --git a/server/pkg/external/listmonk/api.go b/server/pkg/external/listmonk/api.go
index f72b267132..43bf548c77 100644
--- a/server/pkg/external/listmonk/api.go
+++ b/server/pkg/external/listmonk/api.go
@@ -3,6 +3,7 @@ package listmonk
import (
"bytes"
"encoding/json"
+ "errors"
"fmt"
"io"
"net/http"
@@ -79,7 +80,7 @@ func GetSubscriberID(endpoint string, username string, password string, subscrib
// Checking if there are any subscribers found
if len(subscriberResp.Data.Results) == 0 {
- return 0, stacktrace.Propagate(err, "")
+ return 0, stacktrace.Propagate(errors.New("subscriber not found"), "")
}
// Extracting the ID from the response
@@ -114,7 +115,14 @@ func SendRequest(method string, url string, data interface{}, username string, p
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return stacktrace.Propagate(err, "")
+ body, readErr := io.ReadAll(resp.Body)
+ if readErr != nil {
+ return stacktrace.Propagate(readErr, "")
+ }
+ return stacktrace.Propagate(
+ fmt.Errorf("listmonk request failed with status %d: %s", resp.StatusCode, strings.TrimSpace(string(body))),
+ "",
+ )
}
return nil