Skip to content

Commit

Permalink
error handling - fix output 500 error content
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Nov 7, 2021
1 parent ec35713 commit eb23200
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/parts/ProcessResponse.ps1
Expand Up @@ -12,7 +12,7 @@ $requestStatus = [Thycotic.PowerShell.Common.RequestStatus]@{
ResponseUri = $Response.ResponseUri
}
New-Variable -Name tssLastResponse -Value $requestStatus -Description "Contains request status object for the command's last web request" -Visibility Public -Scope Global -Force -WhatIf:$false
if (-not $Response.IsSuccessful) {
if (-not $Response.IsSuccessful -or ($Response.StatusCode -ne 200)) {
if ($Response.ErrorException -is [System.Net.WebException]) {
$exc = [Exception]::new($Response.ErrorException)
$err = [System.Management.Automation.ErrorRecord]::new(
Expand All @@ -22,6 +22,15 @@ if (-not $Response.IsSuccessful) {
$invokeParams.Uri
)
$PSCmdlet.ThrowTerminatingError($err)
} elseif ($Response.StatusCode -eq 500) {
$exc = [Exception]::new($Response.StatusDescription)
$err = [System.Management.Automation.ErrorRecord]::new(
$exc,
$Response.StatusCode,
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Response.ResponseUri
)
$PSCmdlet.ThrowTerminatingError($err)
} else {
$errorContent = $Response.Content
$PSCmdlet.WriteError([Management.Automation.ErrorRecord]::new([Exception]::new($errorContent),"ResultError", "NotSpecified", $invokeParams.Uri))
Expand Down

0 comments on commit eb23200

Please sign in to comment.