ending block on specific error

i classified http reponses on: 200, 504, other.
I wont achieve following behavior:

  1. If other then end block
  2. If 504 then repeat request and save KO - i have code which repeat request based on asLongAs
  3. If 200 then save OK, go to next request

I have huge problem:

  • i cant use exitBlockOnFail and check if response is 200 because then my block is ending when 504 occurred
  • i cant use exitBlockOnFail and check if response is 200 or 504 because i have OK when 504 occurred
  • i cant use exitHereIfFailed when reponse is not equal to 200,504 because all simulation will be stop - but i wont only break block

Have you any ideas to solve my problem ?

You can use optional with checks to save response code and use doIf conditions to call the request. http://gatling.io/docs/2.1.7/general/scenario.html?highlight=doif#conditional-statements

i don’t understand what i can do in my case using doIf.
can you write some pseudo-code ? i would be greteful.

i don’t understand what i can do in my case using doIf.
can you write some pseudo-code ? i would be greteful.

I was thinking something along the following lines.


val request1 = exec(http(“request1”).

{ exec(test) }


Actually there is another way. Give it a try.


val request1=exec(http(“request1”).

val request2 = exec(http(“request2”)…

val conditionalRequest = asLongAs("${myCheck}", ‘504’) {

val user = scenario(“S4Search”).during(20 second){
pace(2 seconds)


I have similar code to the last one. But if i do in this way gatling don’t save 504 response as KO - unless i don’t understand sth

I mean 504 won’t save as KO if in request1 in accept 200 on 504. If don’t write status check - default checking cause that 504 will be save as KO - but then if i all this code use in exitBlockOnFail then block will be break - but i don’t wont it. Breaking block is expected in the case of other errors

I didn’t write a check for 504. By default, Gatling look for 200 or 304 http and fails other status codes. We are only capturing what status code is in request1. If it is 504 then call that again and gatling should fail it.

Can you share you simulation?

But if i wrap by code in exitBlockOnFail then if request failed (for. ex. because return 504) block is immediately stop.
And this is good behavior for all failing reason except 504.

repeat(10) { exitBlockOnFail { val req = exec { http("request") .post("path") .body(StringBody("stringBody")) .check(status.saveAs("statusCode"), status.is(200), jsonPath("jPath").find.optional.saveAs(productOrderIdKey)) } req.asLongAs(session => session("statusCode").as[Int] == 504) { exec(req) } } }

In this code asLongAs will be never call because when 504 occur when exitBlockOnFail exit block

Then don’t use exitBlock. If you look at the way I suggested, it should work.

But if i don’t use exitBlockOnFail then if some error occure, and we go to next request - i don’t wont this. Why? Subsequent requests will be crated based on the previous. So if response of previous will be KO then creating next request failed (f. ex. some needed session key not exists, because it should be set by previous exec).
Maybe instead use exitBlockOnFail i should all request wrap in IF (lastResponse == 200) ?

Thanks for help.
As i say in previous entry I use couple if statement instead exitBlockOnFail. Code is unfortunately less dry, but now it work as i wont.

Thanks again for commitment.

Mind sharing a sample of your solution? I have the a similar requirement (401 instead of 504) and am starting to struggle some.

I have similar issue with status code that I got on the first exec.I need to decide if I got 200 it is GOOD and I want to continue my next exec.
If I got 404 or 409 I need to perform the first exec but with next value which I take from the foreach record.
How I can do this?

def cis_delete_ga() = {

val records = csv(“1.csv”).readRecords

println(“Number of GA:” + records.size)

foreach(records, “record”) {

exec(session => {

session.set(“delete_continue”, “”)


val req = exec(http(“T07_Delete_GlobalAccount”)








req.asLongAs(session => session(“status_ga_delete”).as[Int] == 404 || session(“status_ga_delete”).as[Int] == 409 ) {





Best Regards,