Skip to content

Commit

Permalink
Issue #3151 (#3155)
Browse files Browse the repository at this point in the history
Get-AppSourceProduct returns 404 Not Found

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Aug 12, 2023
1 parent 1627b06 commit 4503352
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
60 changes: 39 additions & 21 deletions AppSource/Invoke-IngestionAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function Invoke-IngestionApiRestMethod {
[string] $query = '',
[Parameter(Mandatory=$false)]
[string] $body = '',
[switch] $silent
[switch] $silent,
[switch] $ignore404
)

$authContext = Renew-BcAuthContext -bcAuthContext $authContext
Expand Down Expand Up @@ -53,20 +54,35 @@ function Invoke-IngestionApiRestMethod {
}
catch {
$statusCode = 0
try {
$errorDetails = $_.ErrorDetails | ConvertFrom-Json
$statusCode = $errorDetails.statusCode
if ($_.Exception -is [System.Net.WebException]) {
$webException = [System.Net.WebException]$_.Exception
$webResponse = $webException.Response
if ($webResponse) {
$statusCode = [int]$webResponse.StatusCode
}
}
catch {}
if ($retries -gt 0 -and $statusCode -eq 500) {
$retries--
Write-Host "$(GetExtendedErrorMessage $_)".TrimEnd()
Write-Host "...retrying in $waittime minute(s)"
Start-Sleep -Seconds ($waitTime*60)
$waitTime = $waitTime * 2
if ($statusCode -eq 404 -and $ignore404) {
# fix for bug https://github.com/microsoft/navcontainerhelper/issues/3151
Write-Host -ForegroundColor Yellow "WARNING: Ingestion API returned an invalid nextlink, ignoring..."
$success = $true
}
else {
throw (GetExtendedErrorMessage $_)
try {
$errorDetails = $_.ErrorDetails | ConvertFrom-Json
$statusCode = $errorDetails.statusCode
}
catch {}

elseif ($retries -gt 0 -and $statusCode -eq 500) {
$retries--
Write-Host "$(GetExtendedErrorMessage $_)".TrimEnd()
Write-Host "...retrying in $waittime minute(s)"
Start-Sleep -Seconds ($waitTime*60)
$waitTime = $waitTime * 2
}
else {
throw (GetExtendedErrorMessage $_)
}
}
}
} while (!$success)
Expand Down Expand Up @@ -128,18 +144,20 @@ function Invoke-IngestionApiGetCollection {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$nextlink = $path
$ignore404 = $false
while ($nextlink) {

$ps = Invoke-IngestionApiRestMethod -authContext $authContext -method GET -headers $headers -path $nextlink -query $query -silent:$silent
$ps = Invoke-IngestionApiRestMethod -authContext $authContext -method GET -headers $headers -path $nextlink -query $query -silent:$silent -ignore404:$ignore404

if ($ps.PSObject.Properties.Name -eq 'nextlink') {
$nextlink = $ps.nextlink.SubString("v1.0/ingestion".Length)
}
else {
$nextlink = ""
}
if ($ps.value) {
$ps.value
$nextlink = ""
if ($ps) {
if ($ps.PSObject.Properties.Name -eq 'nextlink') {
$nextlink = $ps.nextlink.SubString("v1.0/ingestion".Length)
$ignore404 = $true
}
if ($ps.value) {
$ps.value
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
5.0.6
Issue #3151 Get-AppSourceProduct returns 404 Not Found

5.0.5
Add new option (exitedContainers) on Flush-ContainerHelperCache. Note that exited containers are NOT remove by the all flag, you need all,exitedContainers
Expand Down

0 comments on commit 4503352

Please sign in to comment.