Switch on HTTP status


I make HTTP requests to a service where success is indicated by either 200 or 204 (no content). I parse the response using jsonPath, however, as expected this fails when the status is 204. How can I switch on the status, save it as a session variable and only parse the response body when the status is 200?

val scn = scenario("Users Pool 1") .feed(<feeder>) .exec( http("Request 1") .post(<url>) .headers(<headers>) .body(ELFileBody("bodies/request_body.tpl")) // I need the equivalent of "if status == 200 do" here. // I also want to store the http status for later. .check(status.in(200 to 204)) .check(jsonPath("$.id").saveAs("resA")) .check(jsonPath("$.xxx[0].y[0].z").saveAs("resB")) .check(jsonPath("$.xxx[0].y[0].v").ofType[Float].saveAs("resC")) ) // doIf exec based on previous call

Thank you,

Gatling version is 2.1.4

The best you can do is to use optional on the check that might fail.

.check(status.in(200 to 204))

I think the above check works on the Range(200, 201, 202, 203, 204) and not just 200 or 204.

I think this will check the desired status codes.
.check(status.in(Seq(200, 204)))


Thanks for the reply.