Skip to content

Handle permissions API errors gracefully in UpdateUserScopesAsync#1571

Open
waldekmastykarz wants to merge 3 commits intodotnet:mainfrom
waldekmastykarz:fix/handle-permissions-api-404
Open

Handle permissions API errors gracefully in UpdateUserScopesAsync#1571
waldekmastykarz wants to merge 3 commits intodotnet:mainfrom
waldekmastykarz:fix/handle-permissions-api-404

Conversation

@waldekmastykarz
Copy link
Collaborator

When the permissions API returns a 404 for an unrecognized Graph endpoint (e.g. /users/{email}/mailFolders/inbox), the HttpRequestException from that single call caused the entire Task.WhenAll in UpdateUserScopesAsync to fail. This bubbled up to DetermineMinimalScopesAsync, which caught the exception and returned null, preventing all permissions from being reported.

This fix wraps individual HTTP calls with error handling so that a failed request is logged as a warning and skipped, allowing the remaining permissions to be reported correctly.

Fixes #1565

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 dotnet#1565

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@waldekmastykarz waldekmastykarz requested a review from a team as a code owner February 28, 2026 10:11
Copilot AI review requested due to automatic review settings February 28, 2026 10:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the resilience of Graph minimal-permissions scope calculation by preventing a single failing permissions-API call (e.g., 404 for an unrecognized endpoint) from breaking the entire scope-update flow in UpdateUserScopesAsync.

Changes:

  • Wrap individual GetFromJsonAsync calls in UpdateUserScopesAsync with HttpRequestException handling so failures are logged and skipped.
  • Allow remaining successful permissions lookups to continue so minimal permissions can still be reported.

@waldekmastykarz waldekmastykarz added the pr-bugfix Fixes a bug label Feb 28, 2026
waldekmastykarz and others added 2 commits February 28, 2026 11:30
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: GraphMinimalPermissionsPlugin / GraphMinimalPermissionsGuidancePlugin - 404 Error on certain API's

2 participants