Retrying a code block on 401

I have this in lib.scala
def authenticate(username: String, password: String): ChainBuilder = {
exec(flushCookieJar)
.exec(http(“test”)
.post(AuthnEndpoint)
.disableUrlEncoding
.headers(getXAuthHeaders(username, password))
.check(status.in(200,401)).saveAs(“auth_resp_code”)
.check(jsonPath("$.tokenId").find.saveAs(“token”)))
}

And this in run.scala
exec(lib.authenticate("${username}", userPassword )
.doIf(session => session(“auth_resp_code”).as[Int] == 401)) {
exec(lib.authenticate("${username}", userPassword))
}

I want to retry authenticate() if it fails for the first time with a 401. Furthermore i don’t want the 401 to be counted towards a KO.

Is this the correct approach?

And in the “doIf” block is there a way from me to see if it is being executed. How could i do something like println(“i am here”)

Regards,

No need to reply…this works quite nicely :slight_smile: