mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
update error reporting for custom-api JSON validation
- show the request error on non-200 responses
This commit is contained in:
parent
1cf4f520f8
commit
7a8f70db02
@ -203,13 +203,18 @@ func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customA
|
|||||||
body := strings.TrimSpace(string(bodyBytes))
|
body := strings.TrimSpace(string(bodyBytes))
|
||||||
|
|
||||||
if !req.SkipJSONValidation && body != "" && !gjson.Valid(body) {
|
if !req.SkipJSONValidation && body != "" && !gjson.Valid(body) {
|
||||||
truncatedBody, isTruncated := limitStringLength(body, 100)
|
if 200 <= resp.StatusCode && resp.StatusCode < 300 {
|
||||||
if isTruncated {
|
truncatedBody, isTruncated := limitStringLength(body, 100)
|
||||||
truncatedBody += "... <truncated>"
|
if isTruncated {
|
||||||
|
truncatedBody += "... <truncated>"
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Error("Invalid response JSON in custom API widget", "url", req.httpRequest.URL.String(), "body", truncatedBody)
|
||||||
|
return nil, errors.New("invalid response JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Error("Invalid response JSON in custom API widget", "url", req.httpRequest.URL.String(), "body", truncatedBody)
|
return nil, errors.New(fmt.Sprintf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode)))
|
||||||
return nil, errors.New("invalid response JSON")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data := &customAPIResponseData{
|
data := &customAPIResponseData{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user