sailpoint-oss / powershell-sdk

PowerShell Module for accessing SailPoint IdentityNow APIs
https://developer.sailpoint.com/
MIT License
21 stars 15 forks source link

Samples error handling obscure error details #4

Closed rob-buskens-sp closed 1 year ago

rob-buskens-sp commented 1 year ago

Not that the samples don't work or aren't good as is. However when extending them the exception handling fail if the search exception result isn't in json format.

} catch {
    Write-Host $_
    Write-Host ("Exception occurred when calling Invoke-ListAccounts: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))
    Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))
}

In the above, if the $_.ErrorDetails isn't json, then it fails and the error isn't shown.

In the example, remove the sort information to force a bad request. and you'll get:

ConvertFrom-Json: /Users/rob.buskens/Documents/Code2/idn-data-extract/idn-id-invoke-paginate.ps1:20:95 Line | 20 | … ng Invoke-ListAccounts: {0}" -f ($_.ErrorDetails | ConvertFrom-Json)) | ~~~~~~~~~~~~~~~~ | Cannot bind argument to parameter 'InputObject' because it is null. Exception occurred when calling Invoke-ListAccounts: Response headers: null

Whereas the actual error is: Exception occurred when calling Search-Post:System.Management.Automation.RuntimeException: Error! The required Search parameter must include exactly one sort parameter to paginate properly. Response headers: null

tyler-mairose-sp commented 1 year ago

Hello @rob-buskens-sp,

I have updated the exception handling in the example scripts to actually log out the error details. This is fixed in https://github.com/sailpoint-oss/powershell-sdk/pull/19