update error reporting for custom-api JSON validation

- show the request error on non-200 responses
This commit is contained in:
anxdpanic 2025-04-16 22:46:33 -04:00
parent 1cf4f520f8
commit 7a8f70db02

View File

@ -203,6 +203,7 @@ 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) {
if 200 <= resp.StatusCode && resp.StatusCode < 300 {
truncatedBody, isTruncated := limitStringLength(body, 100) truncatedBody, isTruncated := limitStringLength(body, 100)
if isTruncated { if isTruncated {
truncatedBody += "... <truncated>" truncatedBody += "... <truncated>"
@ -212,6 +213,10 @@ func fetchCustomAPIRequest(ctx context.Context, req *CustomAPIRequest) (*customA
return nil, errors.New("invalid response JSON") return nil, errors.New("invalid response JSON")
} }
return nil, errors.New(fmt.Sprintf("%d %s", resp.StatusCode, http.StatusText(resp.StatusCode)))
}
data := &customAPIResponseData{ data := &customAPIResponseData{
JSON: decoratedGJSONResult{gjson.Parse(body)}, JSON: decoratedGJSONResult{gjson.Parse(body)},
Response: resp, Response: resp,