Skip to content

Commit ed5be4d

Browse files
committed
Fix: error handling in Get-GraphToken to fix "Conversion from JSON failed with error: Unexpected character encountered while parsing value: R. Path '', line 0, position 0" error
1 parent 3b917c6 commit ed5be4d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Modules/CIPPCore/Public/GraphHelper/Get-GraphToken.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,14 @@ function Get-GraphToken($tenantid, $scope, $AsApp, $AppID, $AppSecret, $refreshT
9595
}
9696
}
9797
$Tenant.LastGraphError = if ( $_.ErrorDetails.Message) {
98-
$msg = $_.ErrorDetails.Message | ConvertFrom-Json
99-
"$($msg.error):$($msg.error_description)"
98+
if (Test-Json $_.ErrorDetails.Message -ErrorAction SilentlyContinue) {
99+
$msg = $_.ErrorDetails.Message | ConvertFrom-Json
100+
"$($msg.error):$($msg.error_description)"
101+
} else {
102+
"$($_.ErrorDetails.Message)"
103+
}
100104
} else {
101-
$_.Exception.message
105+
$_.Exception.Message
102106
}
103107
$Tenant.GraphErrorCount++
104108

0 commit comments

Comments
 (0)