Skip to content

Commit 90d8857

Browse files
authored
Merge pull request #453 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 01b207d + 0766403 commit 90d8857

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Modules/CIPPCore/Public/GraphHelper/New-GraphGetRequest.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function New-GraphGetRequest {
5959
$RetryCount = 0
6060
$MaxRetries = 3
6161
$RequestSuccessful = $false
62-
Write-Host "This is attempt $($RetryCount + 1) of $MaxRetries"
62+
Write-Information "GET [ $nextURL ] | tenant: $tenantid | attempt: $($RetryCount + 1) of $MaxRetries"
6363
do {
6464
try {
6565
$GraphRequest = @{
@@ -117,11 +117,24 @@ function New-GraphGetRequest {
117117
} catch {
118118
$ShouldRetry = $false
119119
$WaitTime = 0
120-
121120
try {
122-
$Message = ($_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction SilentlyContinue).error.message
121+
$MessageObj = $_.ErrorDetails.Message | ConvertFrom-Json -ErrorAction SilentlyContinue
122+
if ($MessageObj.error) {
123+
$MessageObj | Add-Member -NotePropertyName 'url' -NotePropertyValue $nextURL -Force
124+
$Message = $MessageObj.error.message -ne '' ? $MessageObj.error.message : $MessageObj.error.code
125+
}
123126
} catch { $Message = $null }
124-
if ($Message -eq $null) { $Message = $($_.Exception.Message) }
127+
128+
if ([string]::IsNullOrEmpty($Message)) {
129+
$Message = $($_.Exception.Message)
130+
$MessageObj = @{
131+
error = @{
132+
code = $_.Exception.GetType().FullName
133+
message = $Message
134+
url = $nextURL
135+
}
136+
}
137+
}
125138

126139
# Check for 429 Too Many Requests
127140
if ($_.Exception.Response.StatusCode -eq 429) {
@@ -147,7 +160,7 @@ function New-GraphGetRequest {
147160
} else {
148161
# Final failure - update tenant error tracking and throw
149162
if ($Message -ne 'Request not applicable to target tenant.' -and $Tenant) {
150-
$Tenant.LastGraphError = $Message
163+
$Tenant.LastGraphError = [string]($MessageObj | ConvertTo-Json -Compress)
151164
if ($Tenant.PSObject.Properties.Name -notcontains 'GraphErrorCount') {
152165
$Tenant | Add-Member -MemberType NoteProperty -Name 'GraphErrorCount' -Value 0 -Force
153166
}

Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ function Get-GraphRequestList {
8686
$SingleTenantThreshold = 8000
8787
Write-Information "Tenant: $TenantFilter"
8888
$TableName = ('cache{0}' -f ($Endpoint -replace '[^A-Za-z0-9]'))[0..62] -join ''
89-
Write-Information "Table: $TableName"
9089
$Endpoint = $Endpoint -replace '^/', ''
9190
$DisplayName = ($Endpoint -split '/')[0]
9291

@@ -123,7 +122,6 @@ function Get-GraphRequestList {
123122
}
124123
$GraphQuery.Query = $ParamCollection.ToString()
125124
$PartitionKey = Get-StringHash -String (@($Endpoint, $ParamCollection.ToString(), 'v2') -join '-')
126-
Write-Information "PK: $PartitionKey"
127125

128126
# Perform $count check before caching
129127
$Count = 0
@@ -174,7 +172,7 @@ function Get-GraphRequestList {
174172
Write-Information "Total results (`$count): $Count"
175173
}
176174
}
177-
Write-Information ( 'GET [ {0} ]' -f $GraphQuery.ToString())
175+
#Write-Information ( 'GET [ {0} ]' -f $GraphQuery.ToString())
178176

179177
try {
180178
if ($QueueId) {
@@ -196,7 +194,7 @@ function Get-GraphRequestList {
196194
}
197195
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter
198196
$Type = 'Cache'
199-
Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))"
197+
Write-Information "Table: $TableName | PK: $PartitionKey | Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))"
200198
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
201199
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
202200
}

0 commit comments

Comments
 (0)