fix: improve error handling in performCondenseCompression function

fix: routing
This commit is contained in:
alam00000
2026-02-21 14:27:53 +05:30
parent b9499b228a
commit a119837c8a
3 changed files with 23 additions and 25 deletions

View File

@@ -83,25 +83,22 @@ export async function performCondenseCompression(
try {
const result = await pymupdf.compressPdf(fileBlob, options);
return result;
} catch (error: any) {
const errorMessage = error?.message || String(error);
if (
errorMessage.includes('PatternType') ||
errorMessage.includes('pattern')
) {
const fallbackOptions = {
...options,
images: {
...options.images,
enabled: false,
},
};
} catch {
const fallbackOptions = {
...options,
images: {
...options.images,
enabled: false,
},
};
try {
const result = await pymupdf.compressPdf(fileBlob, fallbackOptions);
return { ...result, usedFallback: true };
} catch (fallbackError: any) {
const msg = fallbackError?.message || String(fallbackError);
throw new Error(`PDF compression failed: ${msg}`);
}
throw new Error(`PDF compression failed: ${errorMessage}`);
}
}