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:
@@ -405,9 +405,34 @@ foreach($change in $changes)
|
||||
else
|
||||
{
|
||||
$body = $payload | ConvertTo-Json -Depth 10 -Compress
|
||||
$null = Invoke-GraphRequest "$($objectType.API)/$($obj.id)" -HttpMethod PATCH -Content $body
|
||||
Write-Host " OK: Renamed '$($change.OldName)' -> '$($change.NewName)'" -ForegroundColor Green
|
||||
$success++
|
||||
$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
|
||||
Write-Host " OK: Renamed '$($change.OldName)' -> '$($change.NewName)'" -ForegroundColor Green
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user