Here is an example...

The Get Number of Retries Groovy contains this...

This defines how many times to retry.
The Get Wait Period groovy contains...

This is the number of millis between retries. So, 10 retries with a wait of 2secs is a max of 20 seconds.
The Reset Retries groovy script contains...

This sets our custom property to zero.
The Rest Request step is whatever call you want to make and retry.
The Check Request is where we do our checking and retrying. I've pasted the code instead of a screenshot.
// Initialise some variables.
def status = testRunner.testCase.testSteps["REST Request"].testRequest.response.responseHeaders["#status#"];
def waitTime = context.expand( '${Get Wait Period - Groovy Script#result}' )
def maxRetries = context.expand( '${Get Number of Retries - Groovy Script#result}' )
def retryCountString = context.expand( '${#TestCase#RetryCount}' )
// Convert the retry count from String to Int
def retryCount = Integer.parseInt(retryCountString);
// Let's check the request status. If it worked its 200.
if(status.toString().contains("200")){
// We're good. Do nothing more.
} else {
// Server not ready. Let's retry...
if(retryCount < Integer.parseInt(maxRetries)) {
log.info("Retry ${retryCount} of ${maxRetries}.");
// A small sleep to give a gap inbetween retries.
sleep( Integer.parseInt(waitTime));
// Update the retry count and save it.
retryCount += 1;
testRunner.testCase.setPropertyValue( "RetryCount", retryCount.toString() );
// Let's re-run the step.
testRunner.gotoStepByName("REST Request");
} else {
log.info("Ran out of retries");
}
}