chore: Ensure Graylog session is set before making requests, and added better error handling

This commit is contained in:
Nathan Windisch 2024-07-25 03:11:59 +01:00
parent 4608f33c4a
commit 85c622f894

View File

@ -49,6 +49,7 @@ function Invoke-GraylogRequest {
[string]
$ContentType = "application/json"
)
if (-NOT (Test-GraylogSession -SkipSessionCheck)) { return } # Ensure that the Secrets are set
$Session = Get-Secret Graylog_Session -Vault Graylog -AsPlainText -ErrorAction Stop
$Request = @{
Method = $Method
@ -57,5 +58,6 @@ function Invoke-GraylogRequest {
ContentType = $ContentType
}
if ($Body) { $Request.Body = $Body }
Invoke-RestMethod @Request
try { Invoke-RestMethod @Request }
catch { throw $_.Exception.Message }
}