From 85c622f89452294b03df3138e23d52b65317ed17 Mon Sep 17 00:00:00 2001 From: Nathan Windisch Date: Thu, 25 Jul 2024 03:11:59 +0100 Subject: [PATCH] chore: Ensure Graylog session is set before making requests, and added better error handling --- Functions/Public/Invoke-GraylogRequest.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Functions/Public/Invoke-GraylogRequest.ps1 b/Functions/Public/Invoke-GraylogRequest.ps1 index b5a558f..058dfcf 100644 --- a/Functions/Public/Invoke-GraylogRequest.ps1 +++ b/Functions/Public/Invoke-GraylogRequest.ps1 @@ -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 } } \ No newline at end of file