Skip to content

Commit 36fd9c0

Browse files
Fix: Modernize GDAP relationship termination logging (KelvinTegelaar#2117)
Improve logging and error handling in the GDAP relationship termination function
2 parents c6c50d7 + 6205e97 commit 36fd9c0

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ExecDeleteGDAPRelationship {
1+
function Invoke-ExecDeleteGDAPRelationship {
22
<#
33
.FUNCTIONALITY
44
Entrypoint,AnyTenant
@@ -13,19 +13,23 @@ Function Invoke-ExecDeleteGDAPRelationship {
1313

1414

1515
# Interact with query parameters or the body of the request.
16-
$GDAPID = $Request.Query.GDAPId ?? $Request.Body.GDAPId
16+
$GDAPId = $Request.Query.GDAPId ?? $Request.Body.GDAPId
1717
try {
18-
$DELETE = New-GraphPostRequest -NoAuthCheck $True -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships/$($GDAPID)/requests" -type POST -body '{"action":"terminate"}' -tenantid $env:TenantID
19-
$Results = [pscustomobject]@{'Results' = "Success. GDAP relationship for $($GDAPID) been revoked" }
20-
Write-LogMessage -headers $Headers -API $APIName -message "Success. GDAP relationship for $($GDAPID) been revoked" -Sev 'Info'
18+
$null = New-GraphPostRequest -NoAuthCheck $True -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships/$($GDAPId)/requests" -type POST -body '{"action":"terminate"}' -tenantid $env:TenantID
19+
$Result = "Success. GDAP relationship for $($GDAPId) been revoked"
20+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Info'
21+
$StatusCode = [HttpStatusCode]::OK
2122

2223
} catch {
23-
$Results = [pscustomobject]@{'Results' = "Failed. $($_.Exception.Message)" }
24+
$ErrorMessage = Get-CippException -Exception $_
25+
$Result = "Failed to revoke GDAP relationship for $($GDAPId). Error: $($ErrorMessage.NormalizedError)"
26+
$StatusCode = [HttpStatusCode]::InternalServerError
27+
Write-LogMessage -headers $Headers -API $APIName -message $Result -Sev 'Error' -LogData $ErrorMessage
2428
}
2529

2630
return ([HttpResponseContext]@{
27-
StatusCode = [HttpStatusCode]::OK
28-
Body = $Results
31+
StatusCode = $StatusCode
32+
Body = @{ 'Results' = $Result }
2933
})
3034

3135
}

0 commit comments

Comments
 (0)