Moving back one record on a loop

So I have a cfloop going and accessing an API. Thing is, it is sometimes rate limited. No problem. I have cfsleep to set the delay. The issue is that I need to “redo” that record without copying and pasting the code (I’ll do that if I HAVE to, but I’d rather avoid that spaghetti solution).

If I set #NameOfQuery#.CurrentRow to -1 it’s current value, I don’t think that will work… Will it?

If not, is there something that can say, “Hey. This code messed up. Put this back into the loop for processing.”?

Take a look at this. If the rate limit throws an error which you catch you can then use cfretry to go back to beginning of the try block after a snooze

Exactly what I need. Does it need to be within the <cfcatch> area?

  <cfset RolesArray = serializeJson(RolesArray)> 
  <cfhttp method="Patch" url="">
    <cfhttpparam name="Authorization" type="header" value="Bot #DiscordToken#">
    <cfhttpparam name="User-Agent" type="header" value="DiscordBot (, 0.1)"> 
    <cfhttpparam name="Content-Type" type="header" value="application/json"> 
    <cfhttpparam name="body" type="body" value='{"roles": #RolesArray#}'> 

<cfif JSON.Message is 'You are being rate limited.'> 
  <cfset Seconds = #JSON.retry_after# + 1000> 
  <cfsleep time="#Seconds#"> 

This is something like I want to do. It doesn’t really return an error or
fail in contacting anything… It gets returned a json string that says “You
are being rate limited”. So I don’t think the <cfcatch> would trigger.

Wait… Can I do…

<cfif JSON.Message is 'You are being rate limited.'>
  <cfset Seconds = #JSON.retry_after# + 1000>
  <cfsleep time="#Seconds#">


The only problem there is that if there is ANY error (even not rate
limited), it will just keep trying or does the try no longer see the

Whatever code you are using to determine that a rate limited has occurred can use a cfthrow to create an error then your catch block can have the sleep and retry in

Ah… I see… So I cftry at the top of the loop. Then I’d it happens, CF
throw an error and in the cfcatch, I cfretry. Cool. Thanks.