Skip to content

Commit

Permalink
🐛 retry 404 errors from GDrive images
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Feb 15, 2024
1 parent 538f288 commit 5a6b378
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions baker/GDriveImagesBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
Expand All @@ -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) {
Expand Down

0 comments on commit 5a6b378

Please sign in to comment.