From 8f7c71168a729c3b970d333afb8156f3fa3eac9b Mon Sep 17 00:00:00 2001 From: Juraj Skripsky Date: Tue, 21 Nov 2023 16:17:55 +0100 Subject: [PATCH] More debug output. --- src/Main.fs | 36 +++++++++++++++++++----------------- src/Ntfy.fs | 8 +++++++- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Main.fs b/src/Main.fs index 0bf7cc9..2d6887e 100644 --- a/src/Main.fs +++ b/src/Main.fs @@ -26,26 +26,28 @@ module Main = let main (args: string[]): int = let secrets = getSecretsFromEnvironment () - let log = Logger.createMultiLogger [ - Logger.createConsoleLogger () - Logger.createStringLogger (Ntfy.post secrets.NtfyTopic) - ] - let result = - if isNull secrets.GotCourts.ApiKey || isNull secrets.GotCourts.PhpSessionId then - log.Write (Error, "💥", sprintf "Please set environment variables '%s' and '%s'." apiKeyName phpSessionIdName) + if isNull secrets.GotCourts.ApiKey || isNull secrets.GotCourts.PhpSessionId || isNull secrets.NtfyTopic then + printfn "💥 Please set environment variables '%s', '%s', and '%s'." apiKeyName phpSessionIdName ntfyTopicName 1 else - try - use gotCourtsClient = GotCourts.createClient secrets.GotCourts - let res = Jobs.groundFrostCheck log gotCourtsClient - if Result.isOk res then 0 else 1 + let log = Logger.createMultiLogger [ + Logger.createConsoleLogger () + Logger.createStringLogger (Ntfy.post secrets.NtfyTopic) + ] - with - | exn -> - log.Write (Error, "💥", sprintf "Exception thrown: %A." exn) - 1 - - log.Close () + try + try + use gotCourtsClient = GotCourts.createClient secrets.GotCourts + let res = Jobs.groundFrostCheck log gotCourtsClient + if Result.isOk res then 0 else 1 + + with + | exn -> + log.Write (Error, "💥", sprintf "Exception thrown: %A." exn) + 1 + + finally + log.Close () result diff --git a/src/Ntfy.fs b/src/Ntfy.fs index a24ae53..154b0f4 100644 --- a/src/Ntfy.fs +++ b/src/Ntfy.fs @@ -1,5 +1,6 @@ namespace TcFairplay +open System.Net open System.Net.Http module Ntfy = @@ -14,5 +15,10 @@ module Ntfy = printfn "Posting text to ntfy.sh." let resp = client.PostAsync(url, sc) |> await - printfn "StatusCode: %A" resp.StatusCode + if resp.StatusCode <> HttpStatusCode.OK then + printfn "Error! Reason: %s" resp.ReasonPhrase + printfn "Length of topic name: %d chars." topic.Length + else + printfn "OK." + ()