From ed3f167b18dd3f96c993f91e6a822363cbe0a22c Mon Sep 17 00:00:00 2001 From: Brian Schmitt Date: Fri, 12 Oct 2018 12:48:19 -0400 Subject: [PATCH] Adding better error handling when response is null When domain is inaccessible, response could be null causing the StatusCode to not be populated. --- src/common.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.ps1 b/src/common.ps1 index 8392f6e4d..ef34164eb 100644 --- a/src/common.ps1 +++ b/src/common.ps1 @@ -77,7 +77,7 @@ function _handleException { $handled = $false - if ($ex.Exception.PSObject.Properties.Match('Response').count -gt 0 -and $ex.Exception.Response.StatusCode -ne "BadRequest") { + if ($ex.Exception.PSObject.Properties.Match('Response').count -gt 0 -and $null -ne $ex.Exception.Response -and $ex.Exception.Response.StatusCode -ne "BadRequest") { $handled = $true $msg = "An error occurred: $($ex.Exception.Message)" Write-Warning $msg