Skip to content

Commit

Permalink
Merge pull request #233 from pspete/update-errormessages
Browse files Browse the repository at this point in the history
Update Error Messages
  • Loading branch information
pspete committed Dec 13, 2019
2 parents 1cd975b + ed3f8b0 commit ab5045f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@

### Module update to cover CyberArk 11.1 API features

- Additions
- New Functions
- `New-PASGroup`
- Creates CyberArk Groups
- Requires 11.1
Expand All @@ -21,7 +21,7 @@
- Disable Automatic CPM Management for an Account.
- Requires 10.4+

- Updates
- Updated Functions
- `Set-PASDirectoryMapping`
- MappingAuthorizations parameter no longer accepts pipeline input
- `Add-PASDiscoveredAccount`
Expand All @@ -37,11 +37,13 @@
- Added features introduced in version 11.1
- Expanded options for updating users.

- Fixes
- Fixes & Other Updates
- `Get-PASAccountPassword`
- Fixed incorrectly escaped value for passwords begining with "\"
- `New-PASRequest`
- Fixed incorrect parameter name which prevented requests specifying mulitple access as required being created.
- Error Reporting
- Added more verbose error messages.

## 3.2.37 (Sept 17th 2019)

Expand Down
34 changes: 27 additions & 7 deletions psPAS/Private/Invoke-PASRestMethod.ps1
Expand Up @@ -127,7 +127,8 @@

}

} else {
}
else {

#PWSH
if ($SkipCertificateCheck) {
Expand Down Expand Up @@ -192,7 +193,8 @@
#make web request, splat PSBoundParameters
$APIResponse = Invoke-WebRequest @PSBoundParameters -ErrorAction Stop

} catch [System.UriFormatException] {
}
catch [System.UriFormatException] {

#Catch URI Format errors. Likely $Script:BaseURI is not set; New-PASSession should be run.
$PSCmdlet.ThrowTerminatingError(
Expand All @@ -208,7 +210,8 @@

)

} catch {
}
catch {

$ErrorID = $null
$StatusCode = $($PSItem.Exception.Response).StatusCode.value__
Expand All @@ -225,25 +228,41 @@

throw $PSItem

} Else {
}
Else {

If (-not($StatusCode)) {

#Generic failure message if no status code/response
$ErrorMessage = "Error contacting $($PSItem.TargetObject.RequestUri.AbsoluteUri)"

} ElseIf ($ErrorDetails) {
}
ElseIf ($ErrorDetails) {

try {

#Convert ErrorDetails JSON to Object
$Response = $ErrorDetails | ConvertFrom-Json

#API Error Message
$ErrorMessage = "[$StatusCode] $($Response.ErrorMessage)"

#API Error Code
$ErrorID = $Response.ErrorCode

#Inner error details are present
if ($Response.Details) {

#Join Inner Error Text to Error Message
$ErrorMessage = $ErrorMessage, $(($Response.Details | Select-Object -ExpandProperty ErrorMessage) -join ", ") -join ": "

#Join Inner Error Codes to ErrorID
$ErrorID = $ErrorID, $(($Response.Details | Select-Object -ExpandProperty ErrorCode) -join ",") -join ","

}

} catch {
}
catch {

#If error converting JSON, return $ErrorDetails
#replace any new lines or whitespace with single spaces
Expand All @@ -270,7 +289,8 @@

)

} finally {
}
finally {

#If Session Variable passed as argument
If ($PSCmdlet.ParameterSetName -eq "SessionVariable") {
Expand Down

0 comments on commit ab5045f

Please sign in to comment.