Skip to content

Commit

Permalink
Merge pull request #2842 from microsoftgraph/2795-when-using-in-azure…
Browse files Browse the repository at this point in the history
…chinacloud-environment-find-mggraphpermission-changes-msgraph-api-endpoints-from-china-to-global

Resets graph environment session to its original state.
  • Loading branch information
timayabi2020 authored Jul 12, 2024
2 parents 8ceb1db + 815b63f commit 9ff2b42
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,11 @@ private string QualifyFilePath(string path)
/// </summary>
private void ResetGraphSessionEnvironment()
{
_originalEnvironment = GraphSession.Instance.Environment;
GraphSession.Instance.Environment = _originalEnvironment;
var currentEnvironment = GraphSession.Instance.Environment;
if(currentEnvironment != null && !currentEnvironment.Equals(_originalEnvironment))
{
GraphSession.Instance.Environment = _originalEnvironment;
}
}

#region CmdLet LifeCycle
Expand Down Expand Up @@ -1039,6 +1042,8 @@ private async Task ProcessRecordAsync()
if (ShouldCheckHttpStatus && !isSuccess)
{
var httpErrorRecord = await GenerateHttpErrorRecordAsync(httpResponseMessageFormatter, httpRequestMessage);
// A reset of the GraphSession Environment is required to avoid side effects
ResetGraphSessionEnvironment();
ThrowTerminatingError(httpErrorRecord);
}
await ProcessResponseAsync(httpResponseMessage);
Expand Down

0 comments on commit 9ff2b42

Please sign in to comment.