|
|
|
|
@ -195,6 +195,7 @@ func (req *CustomAPIRequest) initialize() error {
|
|
|
|
|
type customAPIResponseData struct {
|
|
|
|
|
JSON decoratedGJSONResult
|
|
|
|
|
Response *http.Response
|
|
|
|
|
RAW strings
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type customAPITemplateData struct {
|
|
|
|
|
@ -233,6 +234,7 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
|
|
|
|
|
return &customAPIResponseData{
|
|
|
|
|
JSON: decoratedGJSONResult{gjson.Result{}},
|
|
|
|
|
Response: &http.Response{},
|
|
|
|
|
RAW: nil,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -240,7 +242,11 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
|
|
|
|
|
req.bodyReader.Seek(0, io.SeekStart)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client := ternary(req.AllowInsecure, defaultInsecureHTTPClient, defaultHTTPClient)
|
|
|
|
|
client := defaultHTTPClient
|
|
|
|
|
if req.AllowInsecure {
|
|
|
|
|
client = defaultInsecureHTTPClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp, err := client.Do(req.httpRequest.WithContext(ctx))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
@ -261,20 +267,24 @@ func fetchCustomAPIResponse(ctx context.Context, req *CustomAPIRequest) (*custom
|
|
|
|
|
truncatedBody += "... <truncated>"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slog.Error("Invalid response JSON in custom API widget", "url", req.httpRequest.URL.String(), "body", truncatedBody)
|
|
|
|
|
slog.Error("Invalid response JSON in custom API widget",
|
|
|
|
|
"url", req.httpRequest.URL.String(),
|
|
|
|
|
"body", truncatedBody,
|
|
|
|
|
)
|
|
|
|
|
return nil, errors.New("invalid response JSON")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &customAPIResponseData{
|
|
|
|
|
JSON: decoratedGJSONResult{gjson.Parse(body)},
|
|
|
|
|
Response: resp,
|
|
|
|
|
RAW: body,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func fetchAndRenderCustomAPIRequest(
|
|
|
|
|
primaryReq *CustomAPIRequest,
|
|
|
|
|
subReqs map[string]*CustomAPIRequest,
|
|
|
|
|
|