Skip to content

Commit e2cf245

Browse files
committed
Enhance error handling and simplify group filter logic
Improved error handling in `WebContentMetaDataLoader.cs`: - Added a `try-catch` block for JSON deserialization to handle `JsonSerializationException` errors. - Logged errors using `_telemetry.LogError` and initialized `responseMeta` as an empty list on failure. Simplified logic in `UserGroupsCache.cs`: - Added early return for empty `filter.Patterns` to improve clarity. - Removed redundant condition checks and updated comments for better readability and maintainability.
1 parent 4bbc1f3 commit e2cf245

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/AnalyticsEngine/WebJob.Office365ActivityImporter.Engine/ActivityAPI/Loaders/WebContentMetaDataLoader.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ public async Task<List<ActivityReportInfo>> DownloadMetadata(string changeReport
8585
if (!string.IsNullOrEmpty(responseFromServer))
8686
{
8787
// Deserialise the results from the HTTP response
88-
responseMeta = JsonConvert.DeserializeObject<List<ActivityReportInfo>>(responseFromServer);
88+
try
89+
{
90+
responseMeta = JsonConvert.DeserializeObject<List<ActivityReportInfo>>(responseFromServer);
91+
}
92+
catch (JsonSerializationException)
93+
{
94+
_telemetry.LogError($"Could not deserialise to list of {nameof(ActivityReportInfo)} response: '{responseFromServer}'");
95+
responseMeta = new List<ActivityReportInfo>();
96+
}
8997

9098
// Add our own batch ID variable to each response
9199
foreach (var metaData in responseMeta)

src/AnalyticsEngine/WebJob.Office365ActivityImporter.Engine/Graph/User/UserGroupsCache.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ public async Task<bool> IsInGroupsFilter(string upn, UserGroupsFilterModel filte
5858
{
5959
if (filter == null)
6060
throw new ArgumentNullException(nameof(filter));
61+
if (filter.Patterns.Count == 0)
62+
{
63+
return true; // No filter patterns - all groups match
64+
}
65+
6166
var groupsForUser = await GetGroupsForUserAsync(upn);
6267

63-
if (filter.Patterns.Count == 0 || groupsForUser.Count == 0)
68+
if (groupsForUser.Count == 0)
6469
{
65-
return true; // No filter patterns or user has no groups means all groups match
70+
return true; // user has no groups - all groups match
6671
}
6772
return groupsForUser.Any(g => filter.Matches(g));
6873
}

0 commit comments

Comments
 (0)