diff --git a/create-card.js b/create-card.js index 5951633..1863365 100644 --- a/create-card.js +++ b/create-card.js @@ -290,7 +290,13 @@ class CardCreator { * @returns {Promise} A promise representating the construction of the card's image data. */ async createCard(charaId, customImage) { - const response = await fetch(`https://xivapi.com/character/${charaId}?extended=1&data=FC,mimo`); + const characterInfoUrl = `https://xivapi.com/character/${charaId}?extended=1&data=FC,mimo`; + const response = await fetch(characterInfoUrl); + if (!response.ok) { + // Retry once if the request fails + response = await fetch(characterInfoUrl); + } + const data = await response.json(); const canvasSize = this.canvasSize; diff --git a/index.js b/index.js index 2c9149a..910fdc3 100644 --- a/index.js +++ b/index.js @@ -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; }