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"
        }
            
        "*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 | convertfrom-json  | out-string )
                }
                    
                "*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"
                    $_ | fl *
                }                 
            }

        }
        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)"
        }
    }
}