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." + ()