Skip to content

Commit

Permalink
Merge pull request #1307 from flanksource/fix-invalid-json
Browse files Browse the repository at this point in the history
fix: support invalid json bodies with custom tests
  • Loading branch information
moshloop authored Oct 10, 2023
2 parents 1445123 + a5758e6 commit 619dd61
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions checks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,18 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg.

if resp.IsJSON() {
json, err := resp.AsJSON()
if err != nil {
return results.ErrorMessage(err)
} else {
if err == nil {
data["json"] = json.Value
if check.ResponseJSONContent != nil && check.ResponseJSONContent.Path != "" {
err := resp.CheckJSONContent(json.Value, check.ResponseJSONContent)
if err != nil {
return results.ErrorMessage(err)
}
}
} else if check.Test.IsEmpty() {
return results.Failf("invalid json response: %v", err)
} else {
ctx.Tracef("ignoring invalid json response %v", err)
}
}

Expand Down

0 comments on commit 619dd61

Please sign in to comment.