diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index e3feacff5..d78a929a5 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -19,7 +19,10 @@ import ( "github.com/pkg/errors" ) -const mailCategory = "mail" +const ( + numberOfRetries = 3 + mailCategory = "mail" +) // GraphConnector is a struct used to wrap the GraphServiceClient and // GraphRequestAdapter from the msgraph-sdk-go. Additional fields are for @@ -246,11 +249,16 @@ func (gc *GraphConnector) serializeMessages(user string) ([]DataCollection, erro return true } if *message.GetHasAttachments() { - attached, err := gc.client.UsersById(user).MessagesById(*message.GetId()).Attachments().Get() - if err == nil && attached != nil { - message.SetAttachments(attached.GetValue()) + // Retry Loop + for count := 0; count < numberOfRetries; count++ { + attached, err := gc.client.UsersById(user).MessagesById(*message.GetId()).Attachments().Get() + if err == nil && attached != nil { + message.SetAttachments(attached.GetValue()) + break + } } if err != nil { + fmt.Println("Retries exceeded") errs = WrapAndAppend(*message.GetId(), fmt.Errorf("attachment failed: %v ", err), errs) } } diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index a81e9f041..a8f27b452 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -69,8 +69,9 @@ func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_ExchangeDataColl if err != nil { suite.T().Logf("Missing Data: %s\n", err.Error()) } + suite.NotContains(err.Error(), "attachment failed") // TODO Create Retry Exceeded Error exchangeData := collectionList[0] - suite.T().Logf("Full PathData: %s\n", exchangeData.FullPath()) + suite.Greater(len(exchangeData.FullPath()), 2) } func (suite *GraphConnectorIntegrationSuite) TestGraphConnector_restoreMessages() {