gatling Custom validations

Hi,

I am new to gatling and scala.

I want to fail a request, if the json response didn’t match the json schema.
This is my schema validator function.

def validateJsonAgainstSchema(jsonResponseExpr:Expression[String], schemaFile:String)(session: Session): Validation[Session] = {

val jsonResponse=jsonResponseExpr(session)
val jsonSchema = testUtilsObj.readFile(schemaFile)
val schema: JsonNode = asJsonNode(parse(jsonSchema))
val instance: JsonNode = asJsonNode(parse(jsonResponse.get))
val validator = JsonSchemaFactory.byDefault().getValidator
val processingReport = validator.validate(schema, instance)

if (processingReport.isSuccess) {
Success(session)
} else {
println(“validation Failed***”)
println(processingReport.map(.asJson()).mkString("\n"))
Failure(processingReport.map(
.asJson()).mkString("\n"))
}
}

I call this function in exec block as below, and the gatling test passes even if the function returns failure.
.exec(
valObj.validateJsonAgainstSchema("${jsonResponse}",“Schemas/searchQueryResponse.json”) _
)

How to make the call to ‘validateJsonAgainstSchema’ in the request check block. Can some one give me example of implementing custom validations?

Thanks,
Sreelakshmi