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 1 commit
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
11 changes: 11 additions & 0 deletions src/Cohesity.Powershell/Scripts/Utility/Invoke-RestApi.ps1
Expand Up @@ -117,6 +117,17 @@ 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 | Test-Json
}
catch {

$errorMsg = "Invalid JSON format. Unable to parse the JSON string..."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message could be better. Developer needs to understand what the error is, Can you print the response ?
"Unable to read incoming request from server" : $Response

Also test these scenarios:

  1. API which returns Error
  2. Try API which is not in the system
  3. the powershell lint is failing on unrelated error, can you fix that ?

Write-Host $errorMsg
CSLog -Message $_
CSLog -Message $errorMsg -Severity 3
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