500 Response code not counted as KO in simulation log

I am facing a weird issue where in 500 responses are not counted as KO, when I save the status code of the response in a session attribute.
If I remove the check(status.saveAs(“STATUS_CODE”)) from the request, the 500 responses are counted as KO in the report.
I am wondering if this is the intended behaviour?
My Gatling version is 3.5.1 and scala version is 2.13.5

As soon as you add your own check on the status, it replaces the default one.
Your check doesn’t perform any validation on the status.
You should do something like:

check(status.is(200).saveAs(“STATUS_CODE”))

Thanks Stephane! After implementing your suggestion, I noticed that the check is happening, but the status code is not getting saved in the session attribute. I am getting this error in the log file:
00:58:58.179 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-3’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘STATUS_CODE’ is defined’, forwarding to the next one

Is this happening because Gatling moves to the next request as soon as the check fails? Here is my check expression : check(responseTimeInMillis.saveAs(“PREV_REQ_RESP_TIME”), status.is(200).saveAs(“STATUS_CODE”))

Are you trying to both fail the request when the status is not 200 AND always save the status whatever its value?

Yes that’s correct. Works perfectly now. Thanks!
Learned something new today. I am a longtime jmeter user trying out Gatling for the first time today. So far loving it!

Thanks for your kind words :slight_smile: