From 74840f035d563b976eb7667ae149e69ca72b0a88 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 6 Mar 2023 10:56:43 +0530 Subject: [PATCH] Graph ResyncRequired error can also manifest as resyncRequired (#2688) The only change is that the first letter is now small. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/connector/graph/errors.go | 10 ++++++++-- src/internal/connector/graph/errors_test.go | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/internal/connector/graph/errors.go b/src/internal/connector/graph/errors.go index 177baf21e..850e3fe64 100644 --- a/src/internal/connector/graph/errors.go +++ b/src/internal/connector/graph/errors.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "os" + "strings" "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors" "github.com/pkg/errors" @@ -23,7 +24,7 @@ const ( errCodeItemNotFound = "ErrorItemNotFound" errCodeItemNotFoundShort = "itemNotFound" errCodeEmailFolderNotFound = "ErrorSyncFolderNotFound" - errCodeResyncRequired = "ResyncRequired" + errCodeResyncRequired = "ResyncRequired" // alt: resyncRequired errCodeSyncFolderNotFound = "ErrorSyncFolderNotFound" errCodeSyncStateNotFound = "SyncStateNotFound" errCodeResourceNotFound = "ResourceNotFound" @@ -187,7 +188,12 @@ func hasErrorCode(err error, codes ...string) bool { return false } - return slices.Contains(codes, *oDataError.GetError().GetCode()) + lcodes := []string{} + for _, c := range codes { + lcodes = append(lcodes, strings.ToLower(c)) + } + + return slices.Contains(lcodes, strings.ToLower(*oDataError.GetError().GetCode())) } // ErrData is a helper function that extracts ODataError metadata from diff --git a/src/internal/connector/graph/errors_test.go b/src/internal/connector/graph/errors_test.go index 787d32adf..cafbdc35f 100644 --- a/src/internal/connector/graph/errors_test.go +++ b/src/internal/connector/graph/errors_test.go @@ -104,6 +104,17 @@ func (suite *GraphErrorsUnitSuite) TestIsErrInvalidDelta() { err: odErr(errCodeResyncRequired), expect: assert.True, }, + // next two tests are to make sure the checks are case insensitive + { + name: "resync-required oDataErr camelcase", + err: odErr("resyncRequired"), + expect: assert.True, + }, + { + name: "resync-required oDataErr lowercase", + err: odErr("resyncrequired"), + expect: assert.True, + }, } for _, test := range table { suite.Run(test.name, func() {