Skip to content

Commit b811954

Browse files
committed
Fixed error handling
1 parent c55bb47 commit b811954

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

src/StorageGRID-Webscale.psm1

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function Global:Get-SGWAccounts {
232232
$Server = $Global:CurrentSGWServer
233233
}
234234
if (!$Server) {
235-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
235+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
236236
}
237237
}
238238

@@ -295,10 +295,10 @@ function Global:New-SGWAccount {
295295
$Server = $Global:CurrentSGWServer
296296
}
297297
if (!$Server) {
298-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
298+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
299299
}
300300
if ($Server.APIVersion -ge 2 -and !$Password) {
301-
Write-Error "Password required"
301+
Throw "Password required"
302302
}
303303

304304
$Capabilities = '"' + ($Capabilities -split ',' -join '","') + '"'
@@ -315,6 +315,7 @@ function Global:New-SGWAccount {
315315
"capabilities": [ $Capabilities ]
316316
}
317317
"@
318+
}
318319
else {
319320
if ($Quota) {
320321
$Body = @"
@@ -328,6 +329,7 @@ function Global:New-SGWAccount {
328329
"password": "$Password"
329330
}
330331
"@
332+
}
331333
else {
332334
$Body = @"
333335
{
@@ -381,7 +383,7 @@ function Global:Remove-SGWAccount {
381383
$Server = $Global:CurrentSGWServer
382384
}
383385
if (!$Server) {
384-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
386+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
385387
}
386388
}
387389

@@ -427,7 +429,7 @@ function Global:Get-SGWAccount {
427429
$Server = $Global:CurrentSGWServer
428430
}
429431
if (!$Server) {
430-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
432+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
431433
}
432434
}
433435

@@ -485,7 +487,7 @@ function Global:Update-SGWAccount {
485487
$Server = $Global:CurrentSGWServer
486488
}
487489
if (!$Server) {
488-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
490+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
489491
}
490492

491493
if ($Capabilities) {
@@ -575,7 +577,7 @@ function Global:Replace-SGWAccount {
575577
$Server = $Global:CurrentSGWServer
576578
}
577579
if (!$Server) {
578-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
580+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
579581
}
580582

581583
if ($Capabilities) {
@@ -647,7 +649,7 @@ function Global:Update-SGWSwiftAdminPassword {
647649
$Server = $Global:CurrentSGWServer
648650
}
649651
if (!$Server) {
650-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
652+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
651653
}
652654
if ($Server.APIVersion -gt 1) {
653655
Write-Error "This Cmdlet is only supported with API Version 1.0. Use the new Update-SGWPassword Cmdlet instead!"
@@ -714,7 +716,7 @@ function Global:Update-SGWPassword {
714716
$Server = $Global:CurrentSGWServer
715717
}
716718
if (!$Server) {
717-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
719+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
718720
}
719721
if ($Server.APIVersion -lt 2) {
720722
Write-Error "This Cmdlet is only supported with API Version 2.0 and later. Use the old Update-SGWSwiftAdminPassword Cmdlet instead!"
@@ -773,7 +775,7 @@ function Global:Get-SGWAccountUsage {
773775
$Server = $Global:CurrentSGWServer
774776
}
775777
if (!$Server) {
776-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
778+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
777779
}
778780
}
779781

@@ -823,7 +825,7 @@ function Global:Get-SGWAlarms {
823825
$Server = $Global:CurrentSGWServer
824826
}
825827
if (!$Server) {
826-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
828+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
827829
}
828830
}
829831

@@ -872,7 +874,7 @@ function Global:Get-SGWHealth {
872874
$Server = $Global:CurrentSGWServer
873875
}
874876
if (!$Server) {
875-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
877+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
876878
}
877879
}
878880

@@ -915,7 +917,7 @@ function Global:Get-SGWTopologyHealth {
915917
$Server = $Global:CurrentSGWServer
916918
}
917919
if (!$Server) {
918-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
920+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
919921
}
920922
}
921923

@@ -957,7 +959,7 @@ function Global:Get-SGWProductVersion {
957959
$Server = $Global:CurrentSGWServer
958960
}
959961
if (!$Server) {
960-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
962+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
961963
}
962964
}
963965

@@ -999,7 +1001,7 @@ function Global:Get-SGWDNSServers {
9991001
$Server = $Global:CurrentSGWServer
10001002
}
10011003
if (!$Server) {
1002-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1004+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
10031005
}
10041006
}
10051007

@@ -1042,7 +1044,7 @@ function Global:Replace-SGWDNSServers {
10421044
$Server = $Global:CurrentSGWServer
10431045
}
10441046
if (!$Server) {
1045-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1047+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
10461048
}
10471049
}
10481050

@@ -1093,7 +1095,7 @@ function Global:Get-SGWAccountGroups {
10931095
$Server = $Global:CurrentSGWServer
10941096
}
10951097
if (!$Server) {
1096-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1098+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
10971099
}
10981100
}
10991101

@@ -1143,7 +1145,7 @@ function Global:Get-SGWAccountUsage {
11431145
$Server = $Global:CurrentSGWServer
11441146
}
11451147
if (!$Server) {
1146-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1148+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
11471149
}
11481150
}
11491151

@@ -1192,7 +1194,7 @@ function Global:Get-SGWAccountS3AccessKeys {
11921194
$Server = $Global:CurrentSGWServer
11931195
}
11941196
if (!$Server) {
1195-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1197+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
11961198
}
11971199
}
11981200

@@ -1247,7 +1249,7 @@ function Global:Get-SGWAccountS3AccessKey {
12471249
$Server = $Global:CurrentSGWServer
12481250
}
12491251
if (!$Server) {
1250-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1252+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
12511253
}
12521254
}
12531255

@@ -1303,7 +1305,7 @@ function Global:New-SGWAccountS3AccessKey {
13031305
$Server = $Global:CurrentSGWServer
13041306
}
13051307
if (!$Server) {
1306-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1308+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
13071309
}
13081310

13091311
if ($Expires) {
@@ -1371,7 +1373,7 @@ function Global:Remove-SGWAccountS3AccessKey {
13711373
$Server = $Global:CurrentSGWServer
13721374
}
13731375
if (!$Server) {
1374-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1376+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
13751377
}
13761378
}
13771379

@@ -1415,7 +1417,7 @@ function Global:Get-SGWIdentitySources {
14151417
$Server = $Global:CurrentSGWServer
14161418
}
14171419
if (!$Server) {
1418-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1420+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
14191421
}
14201422
}
14211423

@@ -1518,7 +1520,7 @@ function Global:Update-SGWIdentitySources {
15181520
$Server = $Global:CurrentSGWServer
15191521
}
15201522
if (!$Server) {
1521-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1523+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
15221524
}
15231525
}
15241526

@@ -1585,7 +1587,7 @@ function Global:Sync-SGWIdentitySources {
15851587
$Server = $Global:CurrentSGWServer
15861588
}
15871589
if (!$Server) {
1588-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1590+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
15891591
}
15901592
}
15911593

@@ -1645,7 +1647,7 @@ function Global:Get-SGWReport {
16451647
$Server = $Global:CurrentSGWServer
16461648
}
16471649
if (!$Server) {
1648-
Write-Error "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
1650+
Throw "No StorageGRID Webscale Management Server management server found. Please run Connect-SGWServer to continue."
16491651
}
16501652
}
16511653

0 commit comments

Comments
 (0)