msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
`Invoke-MgGraphRequest` should throw an error when it can't process non-JSON responses
Invoke-MgGraphRequest should throw an error requiring -OutputFilePath when it can't process non-JSON responses and the OutputType is not HttpResponseMessage.
Repro steps
➜ Connect-MgGraph
Welcome To Microsoft Graph!
➜ Invoke-MgGraphRequest -Uri "v1.0/users/$userId/messages/$messageId/`$value" # Should throw an error requiring -OutputFilePath.`
➜ Invoke-MgGraphRequest -Uri "v1.0/users/$userId/messages/$messageId/`$value" -OutputFilePath MessageContent.txt # works
Invoke-MgGraphRequest should also honor -OutputType HttpResponseMessage.
➜ Invoke-MgGraphRequest -Uri "v1.0/users/$userId/messages/$messageId/`$value" -OutputType HttpResponseMessage
@peombwa is there a possibility whereby a customer can attempt to force the response to be of json type by appending this parameter -OutputType Json . For example something like this Invoke-GraphRequest -OutputType Json -Uri "v1.0/users/$userId/messages/$messageId/`$value" ?
@timayabi2020, we can't serialize non-JSON responses to JSON. We should simply throw an error when the specified -OutputType does not match the response content-type. The only exception is -OutputType HttpResponseMessage as non-JSON response content can be held in the Content property.