How to handle multiple responses from server

Hello Team,

I am trying to send one API request towards server and am able to get the response also from server. After that ill read the data using JsonPath.
But I have one condition where in server is not responding with 200 Ok and there by am getting exceptions as am reading the data using JsonPath.

Is there a way to read the response status other than 200 Ok and then discard the response? Also do we have any way to read the empty JsonPath in response.

This is exec1:

        .exec(http("Test")
        .post("MYURL")
        .check(
          status.saveAs("status"),
          checkIf(session => session("status").as[Int] == 200) {

            println(s"Response is 200 OK")
            jsonPath("$..abc").findAll.saveAs("abc")

          },
          checkIf(session => session("status").as[Int] == 502) {
            println("Response is 502 ")
            substring("502 error").exists
          }
        )

In the next exec ill be calling another function based on the response from exec1

This is exec2

      .exec(session => 
       val abcValue = session("abc").as[String])
        If(abcValue = "Test"){
        Print("PASS")
        }else {
       Print("FAIL")}
       )

I was thinking about this case and try some things.
I’m not sure how tryMax and exitHere should works but if as I think then is a bug in Gatling.
I created Issue in GITHUB for that → #4325

Is there a way to read the response status other than 200 Ok and then discard the response?

Also do we have any way to read the empty JsonPath in response.

Sorry, I don’t understand neither of these sentences. Please rephrase and elaborate.

println(s"Response is 200 OK")

This is wrong, it’s going to always print once, when the simulation is instantiated.

I think in this case he want to “ignore in reporting” when status is other than HTTP 200.
I wanted to do it using tryMax and exitHere but behavior of tryMax is little diffrent that I was expected :slight_smile:

So, currently, there’s no way to conditionally ignore some requests.
There’s a way to make them silent, see Gatling - HTTP Request

But the intent of this feature is to exclude from the reporting a feature that’s performed against a server different from the one really under test, eg static assets fetched from a CDN.