Skip to content

Commit cbfbaa2

Browse files
Handle permissions API errors gracefully in UpdateUserScopesAsync (#1571)
* Handle permissions API errors gracefully in UpdateUserScopesAsync When the permissions API returns a 404 for an unrecognized Graph endpoint, the exception from that single call no longer causes the entire Task.WhenAll to fail. Instead, the error is logged as a warning and the endpoint is skipped, allowing the remaining permissions to be reported correctly. Fixes #1565 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix double enumeration of deferred task collection Materialize the task collection with ToArray() and iterate the results from Task.WhenAll instead of re-enumerating the deferred Select, which would trigger duplicate HTTP calls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ef5ec23 commit cbfbaa2

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

DevProxy.Plugins/Utils/GraphUtils.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,23 @@ internal async Task<IEnumerable<string>> UpdateUserScopesAsync(IEnumerable<strin
6666
_logger.LogDebug("Getting permissions for {Method} {Url}", e.Method, e.Url);
6767
return $"{url}&requesturl={e.Url}&method={e.Method}";
6868
});
69-
var tasks = urls.Select(u =>
69+
var tasks = urls.Select(async u =>
7070
{
7171
_logger.LogTrace("Calling {Url}...", u);
72-
return _httpClient.GetFromJsonAsync<GraphPermissionInfo[]>(u);
73-
});
74-
_ = await Task.WhenAll(tasks);
72+
try
73+
{
74+
return await _httpClient.GetFromJsonAsync<GraphPermissionInfo[]>(u);
75+
}
76+
catch (HttpRequestException ex)
77+
{
78+
_logger.LogWarning(ex, "Failed to get permissions for {Url}", u);
79+
return null;
80+
}
81+
}).ToArray();
82+
var results = await Task.WhenAll(tasks);
7583

76-
foreach (var task in tasks)
84+
foreach (var response in results)
7785
{
78-
var response = await task;
7986
if (response is null)
8087
{
8188
continue;

0 commit comments

Comments
 (0)