Skip to content

Commit f2f1edf

Browse files
committed
Updated file to handle non json responses
1 parent 3b0ed09 commit f2f1edf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ internal async Task ProcessResponseAsync(HttpResponseMessage response)
469469
ErrorConstants.Codes.InvokeGraphContentTypeException, returnType);
470470
ThrowIfError(errorRecord);
471471
}
472+
else if (returnType == RestReturnType.Detect)
473+
{
474+
var responseString = await response.Content.ReadAsStringAsync();
475+
WriteObject(responseString);
476+
}
472477
else if (returnType == RestReturnType.OctetStream)
473478
{
474479
var errorRecord =
@@ -594,6 +599,12 @@ private async Task<HttpResponseMessage> GetResponseAsync(HttpClient client, Http
594599

595600
var cancellationToken = _cancellationTokenSource.Token;
596601
var response = await client.SendAsync(request, cancellationToken);
602+
var responseType = response.GetType();
603+
var contentType = response.GetContentType();
604+
if (responseType != typeof(HttpResponseMessage) || (contentType.Equals("text/plain") && String.IsNullOrEmpty(OutputFilePath) && !OutputType.Equals(OutputType.HttpResponseMessage)))
605+
{
606+
throw new ArgumentException("missing -OutputFilePath parameter");
607+
}
597608
return response;
598609
}
599610
}

0 commit comments

Comments
 (0)