mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Fix failing to parse empty response body in custom api widget
This commit is contained in:
parent
176fc896ae
commit
2be59c3eb6
@ -10,6 +10,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@ -90,9 +91,9 @@ func fetchAndParseCustomAPI(req *http.Request, tmpl *template.Template) (templat
|
|||||||
return emptyBody, err
|
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)
|
truncatedBody, isTruncated := limitStringLength(body, 100)
|
||||||
if isTruncated {
|
if isTruncated {
|
||||||
truncatedBody += "... <truncated>"
|
truncatedBody += "... <truncated>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user