How can i retry but ignore first failure

How can do the following usecase?

If a 401 (due to autentication error) is returned, try it again only count the 2nd or later tries as KO.

If i do check(status.in(200,401)) then the 401 is not counted as KO as desired. But in my usecase i want to try twice (or more) before i really give up and record it as KO.

My code is as follows which works but it masks all 401.

tryMax(2) {
exec(flushCookieJar)
.exec(
http(requestName)
.post(AuthnEndpoint)
.disableUrlEncoding
.headers(getXHeaders(username, password))
.check(status.saveAs(“auth_resp_code”))
.check(jsonPath("$.tok").find.optional.saveAs(varName))
)
.doIf(session => session(“auth_resp_code”).as[Int] == 401) {
pause(1)
}
}.exitHereIfFailed

That’s not possible, sorry.

You can either have all failing requests reporting a failure, using tryMax, or have none of them fail, using an asLongAs loop and a check that would allow 401, hence not fail.

So i have tried adding this so that i can re-send the request but now with the standard status check. And i can see in the session “auth_resp_code” → 401, but the doIf condtion is never entered? I wonder why?

.exec { session => println(session); session }
.doIf(session => session(“auth_resp_code”).as[Int] == 401) {
pause(1)
.exec { session => println(session); session }
.exec(
http(requestName)
.post(AuthnEndpoint)
.disableUrlEncoding
.headers(getXHeaders(username, password))
.check(jsonPath("$.token").find.optional.saveAs(varName))
)
}