-
Notifications
You must be signed in to change notification settings - Fork 195
Updated file to handle non json responses #1457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated file to handle non json responses #1457
Conversation
src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs
Outdated
Show resolved
Hide resolved
var responseType = response.GetType(); | ||
var contentType = response.GetContentType(); | ||
if (responseType != typeof(HttpResponseMessage) || (contentType.Equals("text/plain") && String.IsNullOrEmpty(OutputFilePath) && !OutputType.Equals(OutputType.HttpResponseMessage))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-OutputFilePath
is only needed for non-json responses. Let's change the contentType condition to !contentType.Equals("application/json")
.
@timayabi2020, we should return the HTTP response object as a msgraph-sdk-powershell/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs Lines 455 to 457 in f2f1edf
|
@timayabi2020, can't we fix #1425 by changing: msgraph-sdk-powershell/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs Lines 438 to 483 in f2f1edf
var returnType = response.CheckReturnType();
switch (returnType)
{
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);
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;
} This approach limits the change to just |
Co-authored-by: Peter Ombwa <peombwa@microsoft.com>
Fixes #1425
This PR addresses an issue raised here
Changes proposed in this pull request
-OutputType HttpResponseMessage
argument is providedThrows an error
Writes result to console
Writes result to file