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?
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();
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();
Error
error: Error: fetch failed
error: Error: fetch failed
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server