Only convert to json if response content is of json type (#6589)

Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-05-22 10:55:08 -07:00 committed by GitHub
parent 7317d787a2
commit a1aa57222f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 11 deletions

View File

@ -58,7 +58,6 @@ function Submit-Request($filePath, $packageName)
$correlationId = [System.Guid]::NewGuid().ToString()
$headers = @{
"Content-Type" = "application/json"
"x-correlation-id" = $correlationId
}
LogInfo "Request URI: $($uri.Uri.OriginalString)"
@ -67,8 +66,10 @@ function Submit-Request($filePath, $packageName)
{
$Response = Invoke-WebRequest -Method 'GET' -Uri $uri.Uri -Headers $headers -MaximumRetryCount 3
$StatusCode = $Response.StatusCode
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
LogSuccess $responseContent
if ($Response.Headers['Content-Type'] -like 'application/json*') {
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
LogSuccess $responseContent
}
}
catch
{

View File

@ -267,7 +267,6 @@ function Create-API-Review {
$correlationId = [System.Guid]::NewGuid().ToString()
$headers = @{
"Content-Type" = "application/json"
"x-correlation-id" = $correlationId
}
@ -277,13 +276,20 @@ function Create-API-Review {
try
{
$response = Invoke-WebRequest -Method 'GET' -Uri $requestUri.Uri -Headers $headers -MaximumRetryCount 3
if ($response.StatusCode -eq 201) {
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully.`n$($responseContent)"
}
elseif ($response.StatusCode -eq 208) {
$responseContent = $Response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version.`n$($responseContent)"
if ($response.StatusCode -eq 201 -or $response.StatusCode -eq 208) {
if ($response.StatusCode -eq 201) {
LogSuccess "Status Code: $($response.StatusCode)`nAPI review request created successfully"
}
elseif ($response.StatusCode -eq 208) {
LogSuccess "Status Code: $($response.StatusCode)`nThere is no API change compared with the previous version."
}
if ($response.Headers['Content-Type'] -like 'application/json*') {
$responseContent = $response.Content | ConvertFrom-Json | ConvertTo-Json -Depth 10
LogSuccess "Response:`n$($responseContent)"
}
else {
LogSuccess "Response: $($response.Content)"
}
}
else {
LogError "Failed to create API review request. $($response)"