From 817b3b32b12f146392bd9930d305ca998b3a3b79 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sun, 23 Mar 2025 22:57:15 +0100 Subject: [PATCH] return json even if no packages are queued; fix 404 --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index dc5b064..f87b211 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,14 @@ func main() { if *exitCodeFlag { os.Exit(20) } + } else { + log.Debugf("no packages in queue") + if *jsonFlag { + err = json.NewEncoder(os.Stdout).Encode(JSONOut{ + Total: len(packagesInQueue), + Packages: packagesInQueue, + }) + } } } @@ -127,10 +135,10 @@ func ALHPBuildQueuePkgbase() ([]string, error) { } defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("ALHP api returned HTTP %d", resp.StatusCode) - } else if resp.StatusCode == http.StatusNotFound { + if resp.StatusCode == http.StatusNotFound { return nil, nil + } else if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("ALHP api returned HTTP %d", resp.StatusCode) } bResp, err := io.ReadAll(resp.Body)