Skip to content

Commit 780bb1d

Browse files
committed
Preserve PDF download timeouts
1 parent 889e418 commit 780bb1d

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

__tests__/unit/url-reader.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,29 @@ async function runTests() {
14851485
}
14861486
}, results);
14871487

1488+
await testFunction('application/pdf body timeouts preserve the standard timeout error', async () => {
1489+
const mockServer = createMockServer();
1490+
urlCache.clear();
1491+
const { url, close } = await startHttpServer((req, res) => {
1492+
res.writeHead(200, { 'content-type': 'application/pdf' });
1493+
if (req.method === 'HEAD') {
1494+
res.end();
1495+
return;
1496+
}
1497+
res.write('%PDF-');
1498+
});
1499+
1500+
try {
1501+
await assert.rejects(
1502+
fetchAndConvertToMarkdown(mockServer as any, url, 100),
1503+
(error: any) => error.message.includes('Timeout Error'),
1504+
);
1505+
} finally {
1506+
await close();
1507+
urlCache.clear();
1508+
}
1509+
}, results);
1510+
14881511
await testFunction('application/pdf reports malformed and no-text documents without caching them', async () => {
14891512
const mockServer = createMockServer();
14901513
urlCache.clear();

src/url-reader.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ export async function fetchAndConvertToMarkdown(
743743
try {
744744
bodyRead = await readResponseBytesWithLimit(response, effectivePdfLimit);
745745
} catch (error: any) {
746+
if (error?.name === "AbortError") {
747+
throw error;
748+
}
746749
throw createContentError(
747750
`Failed to read PDF content: ${error.message || "Unknown error reading content"}`,
748751
url,

0 commit comments

Comments
 (0)