@@ -8,7 +8,7 @@ function Get-WebServer-ProcessId {
88 $processId = $ (lsof - ti:14141 )
99 }
1010 elseif ($IsWindows ) {
11- $processId = $ (Get-NetTCPConnection - LocalPort 14141 - ErrorAction SilentlyContinue).OwningProcess
11+ $processId = $ (Get-NetTCPConnection - LocalPort 14141 - ErrorAction SilentlyContinue).OwningProcess?[ 0 ]
1212 }
1313 else {
1414 throw [System.Exception ] " Unsupported operating system."
@@ -22,7 +22,11 @@ function Kill-WebServer {
2222
2323 if ($processId -ne $null ) {
2424 Write-Output " Stopping web server"
25- Get-Process - Id $processId | Stop-Process
25+ Get-Process - Id $processId | Stop-Process - ErrorVariable stopErrorMessage
26+
27+ if ($stopErrorMessage ) {
28+ throw " Failed to stop web server: $stopErrorMessage "
29+ }
2630 }
2731}
2832
@@ -40,18 +44,21 @@ function Start-WebServer {
4044Kill- WebServer
4145Start-WebServer
4246
43- Remove-Item - Force - Path .\request-examples \* .json
47+ try {
48+ Remove-Item - Force - Path .\request-examples \* .json
4449
45- $scriptFiles = Get-ChildItem .\request-examples \* .ps1
46- foreach ($scriptFile in $scriptFiles ) {
47- $jsonFileName = [System.IO.Path ]::GetFileNameWithoutExtension($scriptFile.Name ) + " _Response.json"
50+ $scriptFiles = Get-ChildItem .\request-examples \* .ps1
51+ foreach ($scriptFile in $scriptFiles ) {
52+ $jsonFileName = [System.IO.Path ]::GetFileNameWithoutExtension($scriptFile.Name ) + " _Response.json"
4853
49- Write-Output " Writing file: $jsonFileName "
50- & $scriptFile.FullName > .\request-examples \$jsonFileName
54+ Write-Output " Writing file: $jsonFileName "
55+ & $scriptFile.FullName > .\request-examples \$jsonFileName
5156
52- if ($LastExitCode -ne 0 ) {
53- throw [System.Exception ] " Example request from '$ ( $scriptFile.Name ) ' failed with exit code $LastExitCode ."
57+ if ($LastExitCode -ne 0 ) {
58+ throw [System.Exception ] " Example request from '$ ( $scriptFile.Name ) ' failed with exit code $LastExitCode ."
59+ }
5460 }
5561}
56-
57- Kill- WebServer
62+ finally {
63+ Kill- WebServer
64+ }
0 commit comments