Calling a promise recursively I'm trying to call a promise recursively. If I get a responseData with a key error I want to call the promise again and again until I don't get it.

  _getUser (url) {
    console.log('fetching url', url)
    return fetch(`$(url)/api`, {
      method: 'POST',
      headers: {},
      body: '{"key" : "body"}'
    })
    .then((response) =&gt; response.json())
    .then((responseData) =&gt; {
      console.log('Getting responseData', responseData)
      if (responseData[0].error) {
        alert(responseData[0].error.description)
        return _getUser(url)
      } else alert('User Created')
    })
    .catch((error) =&gt; {
      console.log(error)
    })
  }


Is this the best way to call a promise recursively to do what I want?
Two things you can improve:

Retry in all error cases by doing the recursive call in the catch function. 
And limit the number of retries

_getUser (url, triesRemaining) {
    console.log('fetching url', url)
    return fetch(`$(url)/api`, {
      method: 'POST',
      headers: {},
      body: '{"key" : "body"}'
    })
    .then((response) =&gt; response.json())
    .then((responseData) =&gt; {
      console.log('Getting responseData', responseData)
      if (responseData[0].error) {
        alert(responseData[0].error.description)
        throw new Error();
      } else alert('User Created')
    })
    .catch((error) =&gt; {
      console.log(error)
      if(triesRemaining&gt;0) {
        return _getUser(url,triesRemaining-1)
      } else {
        throw new Error('Could not create user. Max amount of tries reached');
      }
    })
  }