Fix failing to parse empty response body in custom api widget
This commit is contained in:
parent
474255c985
commit
31ecd91f7c
1 changed files with 3 additions and 2 deletions
|
@ -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 += "... <truncated>"
|
||||
|
|
Loading…
Add table
Reference in a new issue