Skip to content

Commit

Permalink
🐛 continue correctly on 304 from image fetching (#3197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold authored Feb 15, 2024
1 parent b310119 commit fd511a1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions baker/GDriveImagesBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,28 @@ export const bakeDriveImages = async (bakedSiteDir: string) => {
"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}`
if (response.status === 304) {
// Image has not been modified, skip without logging
return response
} else if (response.ok) {
// Log fetched images if it was success but wasn't 304
console.log(
`Fetching image ${image.filename} from ${remoteFilePath} using etag ${existingEtag}...`
)
return response
} else {
// If the response status is 404, throw an error to trigger retry
const msg = `Fetching image failed: ${response.status} ${response.statusText} ${response.url}`
console.log(msg)
throw new Error(msg)
}
return response
}),
{ maxRetries: 5, exponentialBackoff: true, initialDelay: 1000 }
)

// Image has not been modified, skip
if (response.status === 304) {
return
} else {
// Log fetched images, this should be pretty rare as most images should return 304
console.log(
`Fetching image ${image.filename} from ${remoteFilePath} using etag ${existingEtag}...`
)
}

let buffer = Buffer.from(await response.arrayBuffer())
Expand Down

0 comments on commit fd511a1

Please sign in to comment.