Skip to content

Commit 4044746

Browse files
committed
fix casing and improve logging error handling
1 parent dc2a278 commit 4044746

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Spamfilter/Invoke-AddTenantAllowBlockList.ps1

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-AddTenantAllowBlockList {
1+
function Invoke-AddTenantAllowBlockList {
22
<#
33
.FUNCTIONALITY
44
Entrypoint
@@ -9,14 +9,16 @@ Function Invoke-AddTenantAllowBlockList {
99
param($Request, $TriggerMetadata)
1010

1111
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
1214
$BlockListObject = $Request.Body
13-
if ($Request.Body.tenantId -eq 'AllTenants') { $Tenants = (Get-Tenants).defaultDomainName } else { $Tenants = @($Request.body.tenantId) }
15+
if ($Request.Body.tenantID -eq 'AllTenants') { $Tenants = (Get-Tenants).defaultDomainName } else { $Tenants = @($Request.body.tenantID) }
1416
$Results = [System.Collections.Generic.List[string]]::new()
1517
$Entries = @()
1618
if ($BlockListObject.entries -is [array]) {
1719
$Entries = $BlockListObject.entries
1820
} else {
19-
$Entries = @($BlockListObject.entries -split "[,;]" | Where-Object { $_ -ne "" } | ForEach-Object { $_.Trim() })
21+
$Entries = @($BlockListObject.entries -split '[,;]' | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_.Trim() })
2022
}
2123
foreach ($Tenant in $Tenants) {
2224
try {
@@ -38,19 +40,20 @@ Function Invoke-AddTenantAllowBlockList {
3840
}
3941

4042
New-ExoRequest @ExoRequest
41-
42-
$results.add("Successfully added $($BlockListObject.Entries) as type $($BlockListObject.ListType) to the $($BlockListObject.listMethod) list for $tenant")
43-
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $Tenant -message $result -Sev 'Info'
43+
$Result = "Successfully added $($BlockListObject.Entries) as type $($BlockListObject.ListType) to the $($BlockListObject.listMethod) list for $tenant"
44+
$Results.Add($Result)
45+
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message $Result -Sev 'Info'
4446
} catch {
45-
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
46-
$results.add("Failed to create blocklist. Error: $ErrorMessage")
47-
Write-LogMessage -headers $Request.Headers -API $APIName -tenant $Tenant -message $result -Sev 'Error'
47+
$ErrorMessage = Get-CippException -Exception $_
48+
$Result = "Failed to create blocklist. Error: $($ErrorMessage.NormalizedError)"
49+
$Results.Add($Result)
50+
Write-LogMessage -headers $Headers -API $APIName -tenant $Tenant -message $Result -Sev 'Error' -LogData $ErrorMessage
4851
}
4952
}
5053
return ([HttpResponseContext]@{
5154
StatusCode = [HttpStatusCode]::OK
5255
Body = @{
53-
'Results' = $results
56+
'Results' = $Results
5457
'Request' = $ExoRequest
5558
}
5659
})

Modules/CIPPCore/Public/Entrypoints/Invoke-ListTenantAllowBlockList.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ListTenantAllowBlockList {
1+
function Invoke-ListTenantAllowBlockList {
22
<#
33
.FUNCTIONALITY
44
Entrypoint
@@ -25,7 +25,7 @@ Function Invoke-ListTenantAllowBlockList {
2525
$Results = $ErrorMessage
2626
}
2727
return [HttpResponseContext]@{
28-
StatusCode = $StatusCode
29-
Body = @($Results)
30-
}
28+
StatusCode = $StatusCode
29+
Body = @($Results)
30+
}
3131
}

0 commit comments

Comments
 (0)