Retry Errors From Browser

function retryErrors(delay) {
  return fetch("/rest/issuehub/4.0/errors")
  .then(r => r.json())
  .then(j => {
    console.log(JSON.stringify(j));
    let promise
    if(j.results.length > 0) {
      promise = fetch("/rest/issuehub/4.0/errors/resolve", { method: "POST" })
        .then( r => { console.log(JSON.stringify(r)); return r;  } )
        .then( r => 10 )
    } else {
      const delayWithBackoff = delay * 1.5
      promise = new Promise(r => r(delayWithBackoff))
    }
    return promise
  })
}
function retryLoop(d) {
  setTimeout(function(){
    retryErrors(d)
      .then(retryLoop)
  }, d * 1000)
}
(retryLoop)(1);
function retryErrors(delay) {
  return fetch("/rest/issuehub/4.0/errors")
  .then(r => r.json())
  .then(j => {
    console.log(JSON.stringify(j));
    let promise
    if(j.results.length > 0) {
      promise = fetch("/rest/issuehub/4.0/errors/resolve", { method: "POST" })
        .then( r => { console.log(JSON.stringify(r)); return r;  } )
        .then( r => 10 )
    } else {
      const delayWithBackoff = delay * 1.5
      promise = new Promise(r => r(delayWithBackoff))
    }
    return promise
  })
}
function retryLoop(d) {
  setTimeout(function(){
    retryErrors(d)
      .then(retryLoop)
  }, d * 1000)
}
(retryLoop)(1);