From 2be59c3eb66dc41ce74d8de1f286566f9acfc870 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 1 Mar 2025 23:43:33 +0000 Subject: [PATCH] Fix failing to parse empty response body in custom api widget --- internal/glance/widget-custom-api.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/glance/widget-custom-api.go b/internal/glance/widget-custom-api.go index f7830ce..54db2d7 100644 --- a/internal/glance/widget-custom-api.go +++ b/internal/glance/widget-custom-api.go @@ -10,6 +10,7 @@ import ( "log/slog" "math" "net/http" + "strings" "time" "github.com/tidwall/gjson" @@ -90,9 +91,9 @@ func fetchAndParseCustomAPI(req *http.Request, tmpl *template.Template) (templat return emptyBody, err } - body := string(bodyBytes) + body := strings.TrimSpace(string(bodyBytes)) - if !gjson.Valid(body) { + if body != "" && !gjson.Valid(body) { truncatedBody, isTruncated := limitStringLength(body, 100) if isTruncated { truncatedBody += "... "