@@ -137,8 +137,11 @@ function Start-WebScrapping {
137137 $ExampleLinks = New-Object - TypeName ' System.Collections.ArrayList' ;
138138 $Snippets = New-Object - TypeName ' System.Collections.ArrayList' ;
139139 try {
140- ($readStream , $HttpWebResponse ) = FetchStream - GraphDocsUrl $GraphDocsUrl
141-
140+ ($readStream , $HttpWebResponse , $IsSuccess ) = FetchStream - GraphDocsUrl $GraphDocsUrl
141+ if ($IsSuccess -eq $False ) {
142+ Write-Host " The url $GraphDocsUrl is invalid. Please ensure that the url is correct"
143+ return
144+ }
142145 while (-not $readStream.EndOfStream ) {
143146 $Line = $readStream.ReadLine ()
144147 if ($Line -match " ^### Example" ) {
@@ -223,12 +226,21 @@ function FetchStream {
223226 param (
224227 [string ]$GraphDocsUrl
225228 )
229+ try {
226230 $HttpWebRequest = [System.Net.WebRequest ]::Create($GraphDocsUrl )
227231 $HttpWebResponse = $HttpWebRequest.GetResponse ()
228232 $ReceiveStream = $HttpWebResponse.GetResponseStream ()
229233 $Encode = [System.Text.Encoding ]::GetEncoding(" utf-8" )
230234 $ReadStream = [System.IO.StreamReader ]::new($ReceiveStream , $Encode )
231- return ($ReadStream , $HttpWebResponse )
235+ return ($ReadStream , $HttpWebResponse , $True )
236+ }
237+ catch {
238+ return ($null , $null , $False )
239+ Write-Host " `n Error Message: " $_.Exception.Message
240+ Write-Host " `n Error in Line: " $_.InvocationInfo.Line
241+ Write-Host " `n Error in Line Number: " $_.InvocationInfo.ScriptLineNumber
242+ Write-Host " `n Error Item Name: " $_.Exception.ItemName
243+ }
232244}
233245function Update-ExampleFile {
234246 param (
0 commit comments