Skip to content

Commit 67e66d7

Browse files
Only convert to json if response content is of json type (#41265)
Co-authored-by: Chidozie Ononiwu <[email protected]>
1 parent 94c63f2 commit 67e66d7

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

eng/common/scripts/Detect-Api-Changes.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function Submit-Request($filePath, $packageName)
5858

5959
$correlationId = [System.Guid]::NewGuid().ToString()
6060
$headers = @{
61-
"Content-Type" = "application/json"
6261
"x-correlation-id" = $correlationId
6362
}
6463
LogInfo "Request URI: $($uri.Uri.OriginalString)"
@@ -67,8 +66,10 @@ function Submit-Request($filePath, $packageName)
6766
{
6867
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -Headers $headers -MaximumRetryCount 3
6968
$StatusCode = $Response.StatusCode
70-
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
71-
LogSuccess $responseContent
69+
if ($Response.Headers['Content-Type'] -like 'application/json*') {
70+
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
71+
LogSuccess $responseContent
72+
}
7273
}
7374
catch
7475
{

eng/common/scripts/Helpers/ApiView-Helpers.ps1

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ function Create-API-Review {
267267
$correlationId = [System.Guid]::NewGuid().ToString()
268268

269269
$headers = @{
270-
"Content-Type" = "application/json"
271270
"x-correlation-id" = $correlationId
272271
}
273272

@@ -277,13 +276,20 @@ function Create-API-Review {
277276
try
278277
{
279278
$response = Invoke-WebRequest -Method 'GET' -Uri $requestUri.Uri -Headers $headers -MaximumRetryCount 3
280-
if ($response.StatusCode -eq 201) {
281-
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
282-
LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully.`n$($responseContent)"
283-
}
284-
elseif ($response.StatusCode -eq 208) {
285-
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
286-
LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version.`n$($responseContent)"
279+
if ($response.StatusCode -eq 201 -or $response.StatusCode -eq 208) {
280+
if ($response.StatusCode -eq 201) {
281+
LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully"
282+
}
283+
elseif ($response.StatusCode -eq 208) {
284+
LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version."
285+
}
286+
if ($response.Headers['Content-Type'] -like 'application/json*') {
287+
$responseContent = $response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
288+
LogSuccess "Response:`n$($responseContent)"
289+
}
290+
else {
291+
LogSuccess "Response: $($response.Content)"
292+
}
287293
}
288294
else {
289295
LogError "Failed to create API review request. $($response)"

0 commit comments

Comments
 (0)