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 4902898880
commit fab063f194
4 changed files with 19 additions and 4 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.0
github.com/ProtonMail/gluon v0.16.1-0.20230525065316-a08bb823bbca
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.4.1-0.20230602072524-9e72c2541c15
github.com/ProtonMail/go-proton-api v0.4.1-0.20230605082423-67859aec0317
github.com/ProtonMail/gopenpgp/v2 v2.7.1-proton
github.com/PuerkitoBio/goquery v1.8.1
github.com/abiosoft/ishell v2.0.0+incompatible

4
go.sum
View File

@ -40,8 +40,8 @@ github.com/ProtonMail/go-message v0.13.1-0.20230526094639-b62c999c85b7 h1:+j+Kd/
github.com/ProtonMail/go-message v0.13.1-0.20230526094639-b62c999c85b7/go.mod h1:NBAn21zgCJ/52WLDyed18YvYFm5tEoeDauubFqLokM4=
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
github.com/ProtonMail/go-proton-api v0.4.1-0.20230602072524-9e72c2541c15 h1:gZYur1RURw2LxrOXU6rYM+SdX3G2m9i93w/1uyfPa3k=
github.com/ProtonMail/go-proton-api v0.4.1-0.20230602072524-9e72c2541c15/go.mod h1:+aTJoYu8bqzGECXL2DOdiZTZ64bGn3w0NC8VcFpJrFM=
github.com/ProtonMail/go-proton-api v0.4.1-0.20230605082423-67859aec0317 h1:Mo293UO7CfX1mL+jrBoSrftvhEyq6hyRDia2d6+Kx9U=
github.com/ProtonMail/go-proton-api v0.4.1-0.20230605082423-67859aec0317/go.mod h1:+aTJoYu8bqzGECXL2DOdiZTZ64bGn3w0NC8VcFpJrFM=
github.com/ProtonMail/go-srp v0.0.7 h1:Sos3Qk+th4tQR64vsxGIxYpN3rdnG9Wf9K4ZloC1JrI=
github.com/ProtonMail/go-srp v0.0.7/go.mod h1:giCp+7qRnMIcCvI6V6U3S1lDDXDQYx2ewJ6F/9wdlJk=
github.com/ProtonMail/gopenpgp/v2 v2.7.1-proton h1:YS6M20yvjCJPR1r4ADW5TPn6rahs4iAyZaACei86bEc=

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.