error/error.psm1
Function Get-DDWebException { [CmdletBinding()] [OutputType([int])] Param ( [System.Management.Automation.ErrorRecord]$ExceptionMessage ) $type = $MyInvocation.MyCommand.Name -replace "Get-", "" -replace "WebException", "" switch -Wildcard ($ExceptionMessage.FullyQualifiedErrorId) { "*System.UriFormatException,Microsoft.PowerShell.Commands.Invoke*Command*" { Write-Host -ForegroundColor Magenta "$($ExceptionMessage.Exception.Message)" write-Host "Most likely you are not connected to DataDomain System" write-Host "please use Get-DDtoken -DD_BaseURI" } "System.NullReferenceException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" { Write-Host -ForegroundColor Magenta "$($ExceptionMessage.Exception.Message)" write-Host "Most likely you are not connected to DataDomain System" write-Host "please use Get-DDToken -DD_BASEuri" } "*WebCmdletWebResponseException,Microsoft.PowerShell.Commands.Invoke*Command*" { Write-Host -ForegroundColor Magenta "An Error Occured" switch -Wildcard ($ExceptionMessage.Exception) { "*SSL/TLS secure channel*" { Write-Host -ForegroundColor Magenta $ExceptionMessage Write-Host -ForegroundColor White "SSL/TLS secure channel error indicates untrusted certificates. Connect using -trustCert Option !" } "*302*" { Write-Host -ForegroundColor Magenta "$($ExceptionMessage.Exception.Message)" write-Host "Most likely you Token has been expired" write-Host "please use Get-DDToken -DD_BASEuri" } "*400*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*401*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*403*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*404*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*405*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*406*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*409*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*422*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*428*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*500*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*501*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*502*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*503*" { Write-Host -ForegroundColor Magenta ( $ExceptionMessage | convertfrom-json | out-string ) } "*SSL/TLS*" { } default { Write-Host -ForegroundColor White "general web error" $_ | format-list * } } } default { Write-Host -Foregroundcolor White "$($ExceptionMessage.ToString())" # Write-Host -ForegroundColor Cyan "error not yet declared or no specific returncode" # Write-host -Foregroundcolor Gray "Exception caught at '$($ExceptionMessage.InvocationInfo.InvocationName) ' #Calling Position: $($ExceptionMessage.InvocationInfo.PositionMessage) #$($ExceptionMessage.FullyQualifiedErrorId)" } } } |