@@ -8,7 +8,7 @@ function Get-WebServer-ProcessId {
8
8
$processId = $ (lsof - ti:14141 )
9
9
}
10
10
elseif ($IsWindows ) {
11
- $processId = $ (Get-NetTCPConnection - LocalPort 14141 - ErrorAction SilentlyContinue).OwningProcess
11
+ $processId = $ (Get-NetTCPConnection - LocalPort 14141 - ErrorAction SilentlyContinue).OwningProcess?[ 0 ]
12
12
}
13
13
else {
14
14
throw [System.Exception ] " Unsupported operating system."
@@ -22,7 +22,11 @@ function Kill-WebServer {
22
22
23
23
if ($processId -ne $null ) {
24
24
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
+ }
26
30
}
27
31
}
28
32
@@ -40,18 +44,21 @@ function Start-WebServer {
40
44
Kill- WebServer
41
45
Start-WebServer
42
46
43
- Remove-Item - Force - Path .\request-examples \* .json
47
+ try {
48
+ Remove-Item - Force - Path .\request-examples \* .json
44
49
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"
48
53
49
- Write-Output " Writing file: $jsonFileName "
50
- & $scriptFile.FullName > .\request-examples \$jsonFileName
54
+ Write-Output " Writing file: $jsonFileName "
55
+ & $scriptFile.FullName > .\request-examples \$jsonFileName
51
56
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
+ }
54
60
}
55
61
}
56
-
57
- Kill- WebServer
62
+ finally {
63
+ Kill- WebServer
64
+ }
0 commit comments