Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,45 +436,48 @@ internal async Task ProcessResponseAsync(HttpResponseMessage response)
if (ShouldWriteToPipeline)
{
var returnType = response.CheckReturnType();
if (returnType == RestReturnType.Json)
switch (returnType)
{
var responseString = await response.Content.ReadAsStringAsync();
ErrorRecord error;
switch (OutputType)
{
case OutputType.HashTable:
var hashTable = responseString.ConvertFromJson(true, null, out error);
ThrowIfError(error);
WriteObject(hashTable);
break;
case OutputType.PSObject:
var psObject = responseString.ConvertFromJson(false, null, out error);
ThrowIfError(error);
WriteObject(psObject, true);
break;
case OutputType.HttpResponseMessage:
case RestReturnType.Json:
ErrorRecord error;
string responseString;
switch (OutputType)
{
case OutputType.HashTable:
responseString = await response.Content.ReadAsStringAsync();
var hashTable = responseString.ConvertFromJson(true, null, out error);
ThrowIfError(error);
WriteObject(hashTable);
break;
case OutputType.PSObject:
responseString = await response.Content.ReadAsStringAsync();
var psObject = responseString.ConvertFromJson(false, null, out error);
ThrowIfError(error);
WriteObject(psObject, true);
break;
case OutputType.HttpResponseMessage:
WriteObject(response);
break;
case OutputType.Json:
responseString = await response.Content.ReadAsStringAsync();
WriteObject(responseString);
break;
default:
throw new ArgumentOutOfRangeException(nameof(OutputType));
}
break;
case RestReturnType.OctetStream:
if (OutputType == OutputType.HttpResponseMessage)
WriteObject(response);
break;
case OutputType.Json:
WriteObject(responseString);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
else if (returnType == RestReturnType.Image)
{
var errorRecord =
GetValidationError(Resources.NonJsonResponseWithoutOutputFilePath,
ErrorConstants.Codes.InvokeGraphContentTypeException, returnType);
ThrowIfError(errorRecord);
}
else if (returnType == RestReturnType.OctetStream)
{
var errorRecord =
GetValidationError(Resources.NonJsonResponseWithoutInfer,
ErrorConstants.Codes.InvokeGraphContentTypeException, returnType, response.Content.Headers.ContentDisposition);
ThrowIfError(errorRecord);
else
ThrowIfError(GetValidationError(Resources.NonJsonResponseWithoutInfer, ErrorConstants.Codes.InvokeGraphContentTypeException, returnType, response.Content.Headers.ContentDisposition));
break;
default:
if (OutputType == OutputType.HttpResponseMessage)
WriteObject(response);
else
ThrowIfError(GetValidationError(Resources.NonJsonResponseWithoutOutputFilePath, ErrorConstants.Codes.InvokeGraphContentTypeException, returnType));
break;
}
}
if (ShouldSaveToOutFile)
Expand Down