File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -268,16 +268,28 @@ function Start-ExecuteWithRetry {
268
268
return $res
269
269
} catch [System.Exception] {
270
270
$retryCount++
271
+
272
+ if ($_.Exception -is [System.Net.WebException]) {
273
+ $webResponse = $_.Exception.Response
274
+ # Skip retry on Error: 4XX (e.g. 401 Unauthorized, 404 Not Found etc.)
275
+ if ($webResponse -and $webResponse.StatusCode -ge 400 -and $webResponse.StatusCode -lt 500) {
276
+ # Skip retry on 4xx errors
277
+ Write-Output "Encountered non-retryable error (4xx): $($_.Exception.Message)"
278
+ $ErrorActionPreference = $currentErrorActionPreference
279
+ throw
280
+ }
281
+ }
282
+
271
283
if ($retryCount -gt $MaxRetryCount) {
272
284
$ErrorActionPreference = $currentErrorActionPreference
273
285
throw
274
286
} else {
275
- if($RetryMessage) {
287
+ if ($RetryMessage) {
276
288
Write-Output $RetryMessage
277
- } elseif($_) {
289
+ } elseif ($_) {
278
290
Write-Output $_
279
291
}
280
- Start-Sleep $RetryInterval
292
+ Start-Sleep -Seconds $RetryInterval
281
293
}
282
294
}
283
295
}
You can’t perform that action at this time.
0 commit comments