Retry XIVAPI requests once if they fail

This commit is contained in:
karashiiro 2021-05-31 11:03:21 -07:00
parent e54bffe7fb
commit 1e6aeda945
2 changed files with 13 additions and 5 deletions

View file

@ -24,12 +24,14 @@ var diskCache = cacheManager.caching({
}
});
async function getCharIdByName(world, name) {
var response = await fetch(`https://xivapi.com/character/search?name=${name}&server=${world}`);
var data = await response.json();
async function getCharIdByName(world, name, retries = 1) {
if (retries === -1) return undefined;
const response = await fetch(`https://xivapi.com/character/search?name=${name}&server=${world}`);
const data = await response.json();
if (data.Results[0] === undefined)
return undefined;
return getCharIdByName(world, name, --retries);
return data.Results[0].ID;
}