Skip to content

Commit ec875a7

Browse files
authored
Merge pull request KelvinTegelaar#1664 from kris6673/fix-ListStandardsCompare
Fix: Enhance error handling in licensing checks
2 parents 3e43e65 + be3e918 commit ec875a7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListStandardsCompare.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function Invoke-ListStandardsCompare {
6565

6666
if ($FieldValue -is [System.Boolean]) {
6767
$FieldValue = [bool]$FieldValue
68-
} elseif ($FieldValue -like '*{*') {
68+
} elseif (Test-Json -Json $FieldValue -ErrorAction SilentlyContinue) {
6969
$FieldValue = ConvertFrom-Json -InputObject $FieldValue -ErrorAction SilentlyContinue
7070
} else {
7171
$FieldValue = [string]$FieldValue

Modules/CIPPCore/Public/Functions/Test-CIPPStandardLicense.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ function Test-CIPPStandardLicense {
5555
return $true
5656
} catch {
5757
if (!$SkipLog.IsPresent) {
58-
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Error checking license capabilities for standard $StandardName`: $($_.Exception.Message)" -sev Error
59-
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: Error checking license capabilities - $($_.Exception.Message)" -Tenant $TenantFilter
58+
# Sanitize exception message to prevent JSON parsing issues - remove characters that could interfere with JSON detection
59+
$SanitizedMessage = $_.Exception.Message -replace '[{}\[\]]', ''
60+
Write-LogMessage -API 'Standards' -tenant $TenantFilter -message "Error checking license capabilities for standard $StandardName`: $SanitizedMessage" -sev Error
61+
Set-CIPPStandardsCompareField -FieldName "standards.$StandardName" -FieldValue "License Missing: Error checking license capabilities - $SanitizedMessage" -Tenant $TenantFilter
6062
}
6163
return $false
6264
}

0 commit comments

Comments
 (0)