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
Add verbose logging to Invoke-HttpRequestWithRetry (#530)
Adds Write-Verbose logging to Invoke-HttpRequestWithRetry so HTTP
request details and errors are visible when running with -Verbose.
## Changes
- Log request method, URI, retry config, timeout, and download path on
entry
- Log each attempt number
- Log transient status codes before retrying
- Log final status code on success with SkipHttpErrorCheck
- Log download completion with file path
- Log status code and exception message on errors
Copy file name to clipboardExpand all lines: src/ALZ/Private/Config-Helpers/Edit-ALZConfigurationFilesInPlace.ps1
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,7 @@ function Edit-ALZConfigurationFilesInPlace {
45
45
if ($bicepConfigNode-is [array]) {
46
46
# If this is an array - use the property as an array index...
47
47
if ($propertyNames[$index] -match"[0-9]+"-eq$false) {
48
+
Write-ToConsoleLog"Configuration specifies an array, but the index value '${$propertyNames[$index]}' is not a number. Property path: $($propertyNames-join'.')"-IsError
48
49
throw"Configuration specifies an array, but the index value '${$propertyNames[$index]}' is not a number"
Copy file name to clipboardExpand all lines: src/ALZ/Private/Deploy-Accelerator-Helpers/Invoke-Terraform.ps1
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ function Invoke-Terraform {
46
46
}
47
47
48
48
if ($null-eq$subscriptionId-or$subscriptionId-eq"") {
49
-
Write-Error"Subscription ID not found. Please ensure you are logged in to Azure and have selected a subscription, or provide bootstrap_subscription_id. Use 'az account show' to check."
49
+
Write-ToConsoleLog"Subscription ID not found. Please ensure you are logged in to Azure and have selected a subscription, or provide bootstrap_subscription_id. Use 'az account show' to check."-IsError
Write-ToConsoleLog"Cannot perform upgrade to latest version of '$targetFolder' as unable to determine latest release from GitHub. Current version: $currentVersion"-IsError
92
93
throw"Cannot perform upgrade to latest version as unable to determine latest release from GitHub."
Copy file name to clipboardExpand all lines: src/ALZ/Private/Shared/Get-GithubReleaseTag.ps1
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -72,11 +72,12 @@ function Get-GithubReleaseTag {
72
72
Write-Verbose"Status code: $statusCode"
73
73
74
74
if ($statusCode-eq404) {
75
-
Write-Error"The release $release does not exist in the GitHub repository $githubRepoUrl - $repoReleaseUrl"
75
+
Write-ToConsoleLog"The release $release does not exist in the GitHub repository $githubRepoUrl - $repoReleaseUrl. HTTP status code: $statusCode"-IsError
76
76
throw"The release $release does not exist in the GitHub repository $githubRepoUrl - $repoReleaseUrl"
77
77
}
78
78
79
79
if ($statusCode-ne200) {
80
+
Write-ToConsoleLog"Unable to query repository version from $repoReleaseUrl. HTTP status code: $statusCode"-IsError
80
81
throw"Unable to query repository version, please check your internet connection and try again..."
Write-Verbose"HTTP $Method$Uri - Error on attempt ${attempt}: Status=$responseCode, Message=$($_.Exception.Message)"
172
+
164
173
if ($isTransient-and$attempt-lt$maxAttempts) {
165
-
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
166
175
Start-Sleep-Seconds $RetryIntervalSeconds
167
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)) {
190
+
$errorDetails+=" Response body: $responseBody"
191
+
}
192
+
}
193
+
} catch {
194
+
Write-Verbose"Failed to read response body: $($_.Exception.Message)"
0 commit comments