How to fail a Gatling test from within "exec"?

You have to abide by Gatling APIs.

  1. With checks, you don't "fail" the test, but the request. If you're looking for failing the whole test, you should have a look at the Assertions API and the Jenkins plugin.
  2. You can only perform a Check at the request site, not later. One of the very good reasons is that if you store the bodyString in the Sessions like you're doing, you'll end using a lot of memory and maybe crashing (still referenced, so not garbage collectable). You have to perform your processData in the check, typically in the transform optional step.

were you looking for something like

  .exec(http("getRequest")
    .get("/request/123")
    .headers(headers)
    .check(status.is(200))
    .check(jsonPath("$.request_id").is("123")))