You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Write-ToConsoleLog for warnings and errors in Invoke-HttpRequestWithRetry
- Replace Write-Warning with Write-ToConsoleLog -IsWarning for retry messages
- Add Write-ToConsoleLog -IsError with detailed error info before throwing
- Include status code, exception message, and response body in error output
Copy file name to clipboardExpand all lines: src/ALZ/Private/Shared/Invoke-HttpRequestWithRetry.ps1
+23-2Lines changed: 23 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ function Invoke-HttpRequestWithRetry {
142
142
143
143
if ($code-in$transientStatusCodes-and$attempt-lt$maxAttempts) {
144
144
Write-Verbose"HTTP $Method$Uri - Transient status $code on attempt $attempt"
145
-
Write-Warning"Request to $Uri returned status $code (attempt $attempt of $maxAttempts). Retrying in $RetryIntervalSeconds seconds..."
145
+
Write-ToConsoleLog"Request to $Uri returned status $code (attempt $attempt of $maxAttempts). Retrying in $RetryIntervalSeconds seconds..."-IsWarning
146
146
Start-Sleep-Seconds $RetryIntervalSeconds
147
147
continue
148
148
}
@@ -171,9 +171,30 @@ function Invoke-HttpRequestWithRetry {
171
171
Write-Verbose"HTTP $Method$Uri - Error on attempt $attempt: Status=$responseCode, Message=$($_.Exception.Message)"
172
172
173
173
if ($isTransient-and$attempt-lt$maxAttempts) {
174
-
Write-Warning"Request to $Uri failed with status $responseCode (attempt $attempt of $maxAttempts). Retrying in $RetryIntervalSeconds seconds..."
174
+
Write-ToConsoleLog"Request to $Uri failed with status $responseCode (attempt $attempt of $maxAttempts). Retrying in $RetryIntervalSeconds seconds..."-IsWarning
175
175
Start-Sleep-Seconds $RetryIntervalSeconds
176
176
} else {
177
+
$errorDetails="HTTP $Method$Uri failed after $attempt attempt(s)."
178
+
if ($null-ne$responseCode) {
179
+
$errorDetails+=" Status code: $responseCode."
180
+
}
181
+
$errorDetails+=" Error: $($_.Exception.Message)"
182
+
if ($_.Exception.Response) {
183
+
try {
184
+
$stream=$_.Exception.Response.GetResponseStream()
185
+
if ($null-ne$stream) {
186
+
$reader= [System.IO.StreamReader]::new($stream)
187
+
$responseBody=$reader.ReadToEnd()
188
+
$reader.Dispose()
189
+
if (-not [string]::IsNullOrWhiteSpace($responseBody)) {
0 commit comments