Skip to content

Commit

Permalink
Issue #564
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNaj committed Jan 12, 2016
1 parent edc4822 commit b87476b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 11 additions & 4 deletions Modules/SPE/Receive-RemoteItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,23 @@ function Receive-RemoteItem {
$webclient.Credentials = $Credential
}

[System.Net.HttpWebResponse]$script:errorResponse = $null;
[byte[]]$response = & {
try {
$webclient.DownloadData($url)
$script:errorResponse = $null;
$script:ex = $null
$webclient.DownloadData($url) | Out-Null
} catch [System.Net.WebException] {
[System.Net.WebException]$ex = $_.Exception
[System.Net.HttpWebResponse]$errorResponse = $ex.Response
Write-Verbose -Message "Response status description: $($errorResponse.StatusDescription)"
[System.Net.WebException]$script:ex = $_.Exception
[System.Net.HttpWebResponse]$script:errorResponse = $script:ex.Response
}
}

if($errorResponse){
Write-Error -Message "Server responded with error: $($errorResponse.StatusDescription)" -Category ConnectionError `
-CategoryActivity "Download" -CategoryTargetName $uri -Exception ($script:ex) -CategoryReason "$($errorResponse.StatusCode)" -CategoryTargetType $RootPath
}

if($response -and $response.Length -gt 0) {
$contentType = $webclient.ResponseHeaders["Content-Type"]
$contentDisposition = $webclient.ResponseHeaders["Content-Disposition"]
Expand Down
13 changes: 10 additions & 3 deletions Modules/SPE/Send-RemoteItem.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function Send-RemoteItem {
[byte[]]$response = & {
try {
Write-Verbose -Message "Uploading $($Path)"
[System.Net.HttpWebResponse]$script:errorResponse = $null;
$fileStream = ([System.IO.FileInfo] (Get-Item -Path $Path)).OpenRead()
$bytes = New-Object byte[] 1024
$totalBytesToRead = $fileStream.Length
Expand All @@ -148,12 +149,18 @@ function Send-RemoteItem {
#$webclient.UploadData($url, $data)
Write-Verbose -Message "Upload complete."
} catch [System.Net.WebException] {
[System.Net.WebException]$ex = $_.Exception
[System.Net.HttpWebResponse]$errorResponse = $ex.Response
[System.Net.WebException]$script:ex = $_.Exception
[System.Net.HttpWebResponse]$script:errorResponse = $ex.Response
Write-Verbose -Message "Response exception message: $($ex.Message)"
Write-Verbose -Message "Response status description: $($errorResponse.StatusDescription)"
Write-Verbose -Message "Response status description: $($errorResponse.StatusDescription)"
}
}

if($errorResponse){
Write-Error -Message "Server responded with error: $($errorResponse.StatusDescription)" -Category ConnectionError `
-CategoryActivity "Download" -CategoryTargetName $uri -Exception ($script:ex) -CategoryReason "$($errorResponse.StatusCode)" -CategoryTargetType $RootPath
}

}
}
}

0 comments on commit b87476b

Please sign in to comment.