msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

`Invoke-MgGraphRequest` should throw an error when it can't process non-JSON responses

Open peombwa opened this issue 3 years ago • 1 comments
trafficstars

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 avatar Jul 26 '22 18:07 peombwa

@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 avatar Aug 11 '22 15:08 timayabi2020

@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.

peombwa avatar Aug 16 '22 20:08 peombwa