Skip to content

Commit 1e8e80e

Browse files
authored
Merge pull request #1079 from koskila/fix/1078
Fix #1078 by improving error handling
2 parents ad1162b + 77e83c4 commit 1e8e80e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/lib/PnP.Framework/Extensions/ClientContextExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ public static ClientContext GetSiteCollectionContext(this ClientRuntimeContext c
578578
/// <returns>True if app-only, false otherwise</returns>
579579
public static bool IsAppOnly(this ClientRuntimeContext clientContext)
580580
{
581-
582581
// Set initial result to false
583582
var result = false;
584583

@@ -692,7 +691,18 @@ public static string GetAccessToken(this ClientRuntimeContext clientContext)
692691
};
693692
// Issue a dummy request to get it from the Authorization header
694693
clientContext.ExecutingWebRequest += handler;
695-
clientContext.ExecuteQuery();
694+
try
695+
{
696+
clientContext.ExecuteQuery();
697+
}
698+
catch (Exception ex)
699+
{
700+
// This can fail for whatever reason, but if we already have the AccessToken, it doesn't matter
701+
if (String.IsNullOrEmpty(accessToken))
702+
{
703+
throw new AggregateException("Fetching the AccessToken to inspect whether the ClientContext is AppOnly or not failed. There might be more information in the InnerExceptions.", ex);
704+
}
705+
}
696706
clientContext.ExecutingWebRequest -= handler;
697707
}
698708
}

0 commit comments

Comments
 (0)