Action in case .check block fails.

Is it possible to perform some actions in case my check block fails? For example:

`
.check(regex(“someString”))
.onFailure(exec(doSomething))

`

Cheers,

Pierre

For some reason the actions are taken in both cases (when check fails, and when check succeeds). The full request code looks like this:


exec(http(description)
 .post(someUrl)
 .body(StringBody(requestBody))
 .check(status.is(200))
 .check(regex(checkString)))
 .doIf(session => session.isFailed){
 exec(session => {
 logger.info("someMessage")
 session
 })
 }

But in error report (console) I have 4 OK request and 3 KO. I thought in this case there must be only 3 error messages logged. However, all 7 are logged.

Sorry, false alarm! I probably but the .doIf block in the wrong place. Now its works as intended. Thanks for the tip!

Note that session.isFailed doesn’t account just for the last action, so it might return true because a previous request failed instead.

You might want to save the result of each check and then have your condition verify if one result is missing (meaning that the check failed).