Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception has been caught and custom error implemented while processing the Rest API via cmdlet #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Cohesity.Powershell/Scripts/Utility/Invoke-RestApi.ps1
Expand Up @@ -117,6 +117,20 @@ function Invoke-RestApi {
catch {
# this flag can be optionally used by the caller to identify the details of failure
$Global:CohesityAPIError = $_.Exception
try {
$Global:CohesityAPIError.Message | ConvertFrom-Json;
}
catch {

$cohesityFolder = $Global:CohesityCmdletConfig.ConfigFolder
$logFileName = $Global:CohesityCmdletConfig.LogFileName
$CSLogFilePath = "$HOME/" + $cohesityFolder + "/" + $logFileName
Write-Host "Invalid response from server. Please refer the logs at $CSLogFilePath"
Write-Host $Global:CohesityAPIError.Message
CSLog -Message $Global:CohesityAPIError.Message
CSLog $_
return
}
# to make the ScriptAnalyzer happy
CSLog -Message ($Global:CohesityAPIError | ConvertTo-json) -Severity 3
# capturing the error message from the cluster rather than the powershell framework $_.Exception.Message
Expand Down