Conditionally exit block on failed


I would like to get some suggestions on how to exit a block of requests only when a certain type of failures happen.

For example, I have a scenario of 5 requests:

val scn = scenario(“scenario”).exec(request 1).exec(request 2).exec(request 3).exec(request 4).exec(request 5)

Let request 2,3,4 be a block. I would like to exit block if and only if

  • Any request in the block return 403 status code
  • Request 3 fails

exitHereIfFailed cannot be used because request 5 should always be executed.
exitBlockOnFailed cannot be used because on certain failures the execution should continue (e.g. request 2 returns 500 status code)

So far the only solution I have is to have a doIf around each request in the block:

exec(request 1)
.exec(request 2)
.doIf(status code is not 403) {
exec(request 3)
.doIf(status is ‘OK’) {
exec(request 4)
.exec(request 5)

Does Gatling or Scala provide something like a GOTO statement? Or is it possible to implement an exitBlockOnFailedWithCondition?

Any suggestion/comment is appreciated.


Hi Brian,

Try to think about it the other way around. You can use exitBlockOnFail with a twist, filtering out bad requests one a time, and adding a check on the last request to make sure it didn’t fail, either on status or content.

Something like this:

  .exitBlockOnFail {
        .check(status.not(403))) // "not" is what you wan't
          .check([]( // or any check on content


Obviously, request2 should be inside the block with a check(status.not(403)) and request5 outside the block without any particular check!


Hi Guillaume thanks for the reply :slight_smile:

However, I still want to see KOs in the report for other non 200s status code. For example, if my request 4 returns a 500, a check(status.not(403)) will consider my request as a OK, which it will not show in the report.
Sorry I wasn’t clear on that in the original post, but that is quite important to me. 200 => OK and continue, 403 => KO and exit block, other status code => KO and continue.


I think I can probably solve my issue using asLongAs loop with exitASAP=true. The condition is checked after each call within the loop.