From 5a6b378e07ecb3787d8fd5b2aceea909915cb089 Mon Sep 17 00:00:00 2001 From: Marigold Date: Thu, 15 Feb 2024 08:49:59 +0100 Subject: [PATCH] :bug: retry 404 errors from GDrive images --- baker/GDriveImagesBaker.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/baker/GDriveImagesBaker.tsx b/baker/GDriveImagesBaker.tsx index 07af4644fcf..fe75f4bf824 100644 --- a/baker/GDriveImagesBaker.tsx +++ b/baker/GDriveImagesBaker.tsx @@ -52,6 +52,14 @@ export const bakeDriveImages = async (bakedSiteDir: string) => { headers: { "If-None-Match": existingEtag, }, + }).then((response) => { + // If the response status is 404, throw an error to trigger retry + if (!response.ok) { + throw new Error( + `Fetching image failed: ${response.status} ${response.statusText} ${response.url}` + ) + } + return response }), { maxRetries: 5, exponentialBackoff: true, initialDelay: 1000 } ) @@ -66,12 +74,6 @@ export const bakeDriveImages = async (bakedSiteDir: string) => { ) } - if (!response.ok) { - throw new Error( - `Fetching image failed: ${response.status} ${response.statusText} ${response.url}` - ) - } - let buffer = Buffer.from(await response.arrayBuffer()) if (!image.isSvg) {