Issue with Fetching PDF from Uploadthing in the server
I'm trying to fetch a PDF from Uploadthing in the server, but many time it fails. How can I fix this issue so it always fetches the PDF without problems?
Error
Error
error: Error: fetch failed let response;
let retries = 5;
while (retries > 0) {
try {
response = await fetch(`https://utfs.io/f/${fileKey}`);
if (response.ok) break;
} catch (error) {
console.log(`Fetch failed, retrying... (${3 - retries + 1}/${3})\n\n ${error}`);
}
retries--;
if (retries > 0) await new Promise(resolve => setTimeout(resolve, 1000));
}
if (!response || !response.ok) {
throw new Error('Failed to fetch PDF after multiple retries');
}
const blob = await response.blob();
const loader = new PDFLoader(blob);
const pageLevelDocs = await loader.load();