fix(rename): add retry logic for transient 5xx/429 errors

Settings Catalog and other Graph endpoints occasionally return 500
InternalServerError on PATCH. Retry up to 3 times with a 2s delay
to improve reliability for bulk rename operations.
This commit is contained in:
2026-04-14 18:58:20 +02:00
parent 07c25e897a
commit cd1c004f4b

View File

@@ -405,9 +405,34 @@ foreach($change in $changes)
else else
{ {
$body = $payload | ConvertTo-Json -Depth 10 -Compress $body = $payload | ConvertTo-Json -Depth 10 -Compress
$maxRetries = 3
$retryDelay = 2
$renamed = $false
for($r = 1; $r -le $maxRetries; $r++)
{
try
{
$null = Invoke-GraphRequest "$($objectType.API)/$($obj.id)" -HttpMethod PATCH -Content $body $null = Invoke-GraphRequest "$($objectType.API)/$($obj.id)" -HttpMethod PATCH -Content $body
Write-Host " OK: Renamed '$($change.OldName)' -> '$($change.NewName)'" -ForegroundColor Green Write-Host " OK: Renamed '$($change.OldName)' -> '$($change.NewName)'" -ForegroundColor Green
$success++ $success++
$renamed = $true
break
}
catch
{
$statusCode = $_.Exception.Response.StatusCode
if($r -lt $maxRetries -and ($statusCode -ge 500 -or $statusCode -eq 429))
{
Write-Host " Retry $r/$maxRetries after $retryDelay`s (HTTP $statusCode)..." -ForegroundColor DarkYellow
Start-Sleep -Seconds $retryDelay
}
else
{
throw
}
}
}
if(-not $renamed) { throw "Rename failed after $maxRetries attempts." }
} }
} }
catch catch