feat(GODT-2653): Log API error details on Message import and send

This commit is contained in:
Leander Beernaert
2023-06-05 11:57:51 +02:00
parent cde9c19f71
commit 51315d5d2b
4 changed files with 45 additions and 13 deletions

View File

@ -37,6 +37,7 @@ import (
"github.com/ProtonMail/proton-bridge/v3/pkg/message/parser"
"github.com/bradenaw/juniper/stream"
"github.com/bradenaw/juniper/xslices"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"
)
@ -357,6 +358,12 @@ func (conn *imapConnector) CreateMessage(
err = fmt.Errorf("%v: %w", err, connector.ErrMessageSizeExceedsLimits)
}
if apiErr := new(proton.APIError); errors.As(err, &apiErr) {
logrus.WithError(apiErr).WithField("Details", apiErr.DetailsToString()).Error("Failed to import message")
} else {
logrus.WithError(err).Error("Failed to import message")
}
return msg, literal, err
}

View File

@ -463,7 +463,15 @@ func (user *User) SendMail(authID string, from string, to []string, r io.Reader)
return ErrInvalidRecipient
}
return user.sendMail(authID, from, to, r)
if err := user.sendMail(authID, from, to, r); err != nil {
if apiErr := new(proton.APIError); errors.As(err, &apiErr) {
logrus.WithError(apiErr).WithField("Details", apiErr.DetailsToString()).Error("failed to send message")
}
return err
}
return nil
}
// CheckAuth returns whether the given email and password can be used to authenticate over IMAP or SMTP with this user.