From d17db322628605ca43004b71c3592bd80e256562 Mon Sep 17 00:00:00 2001 From: Daniel Leroux Date: Mon, 16 Sep 2024 16:23:56 +0200 Subject: [PATCH] docs(figma): add retry function after rate limit reached (#1477) --- 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 a7e7e68b73a..749501596f1 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 71b4fe9d2d9..23cc70c3d33 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 () => {};