From 0c7fa9e229499a066a833188f8dd201ffc8dbb78 Mon Sep 17 00:00:00 2001 From: Daniel Leroux Date: Mon, 16 Sep 2024 12:45:46 +0200 Subject: [PATCH] docs(figma): add retry function after rate limit reached --- packages/documentation/docusaurus.config.ts | 2 +- packages/figma-plugin/src/figma.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/documentation/docusaurus.config.ts b/packages/documentation/docusaurus.config.ts index a7e7e68b73..749501596f 100644 --- a/packages/documentation/docusaurus.config.ts +++ b/packages/documentation/docusaurus.config.ts @@ -148,7 +148,7 @@ const config: Config = { // Please change this to your repo. editUrl: 'https://www.github.com/siemens/ix/edit/main/packages/documentation/', - remarkPlugins: useFastStart ? [] : [ + remarkPlugins: [ figmaPlugin({ baseUrl: `${baseUrl}figma`, figmaFolder: `${path.join(__dirname, 'static', 'figma')}`, diff --git a/packages/figma-plugin/src/figma.ts b/packages/figma-plugin/src/figma.ts index 71b4fe9d2d..23cc70c3d3 100644 --- a/packages/figma-plugin/src/figma.ts +++ b/packages/figma-plugin/src/figma.ts @@ -51,7 +51,15 @@ async function getImageResource( 'with node ids:', ids ); - return null; + + if (response.status === 429) { + console.log('🕰️ Retry after 60 seconds'); + return new Promise((resolve) => { + setTimeout(() => { + resolve(getImageResource(fileName, nodeIds, figmaToken)); + }, 60 * 1000); + }); + } } const data = await response.json(); @@ -150,6 +158,7 @@ async function processImage( } export default (config: FigmaConfig) => { + console.log('Figma plugin running'); if (config.apiToken === undefined || config.apiToken === '') { console.error('@siemens/figma-plugin no auth token provided'); return () => {};