Prerequest script for collection to check the status code and retry the trigger

My question:
I am triggering the postman collection with Prerequest script for that collection. In that Pre request script, tried the logic to retry when any unexpected status code got. but getting error(TypeError: Cannot read properties of undefined (reading ā€˜codeā€™) ) when running the script.

Details (like screenshots):

Prerequest script for collection:

Script:

var maxNumberOfTries = 3;
var sleepBetweenTries = 5000;

if (!pm.environment.get(ā€œcollection_triesā€)) {
pm.environment.set(ā€œcollection_triesā€, 1);
}

if ((pm.response.code != 200) && (pm.environment.get(ā€œcollection_triesā€) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ā€œcollection_triesā€), 10);
pm.environment.set(ā€œcollection_triesā€, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);

}else if ((pm.response.code != 201) && (pm.environment.get(ā€œcollection_triesā€) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ā€œcollection_triesā€), 10);
pm.environment.set(ā€œcollection_triesā€, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);

}else if ((pm.response.code !=204) && (pm.environment.get(ā€œcollection_triesā€) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ā€œcollection_triesā€), 10);
pm.environment.set(ā€œcollection_triesā€, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);

}

else {

 pm.environment.unset("collection_tries");
 pm.test("Successful request", () => {
 pm.expect(pm.response.code).to.be.oneOf([200,201,204]);

});

}

This is in a pre-request script which means it runs before the request gets sent.

Therefore ā€œpm.response.codeā€ will be undefined as the request hasnā€™t been sent yet.