Fix encrypted pdf handling (#6088)

Fix and improve encrypted pdf handling
This commit is contained in:
Reece Browne
2026-04-13 13:20:43 +01:00
committed by GitHub
parent d53beb9bce
commit 76aa5c7e2f
12 changed files with 527 additions and 67 deletions
+20 -1
View File
@@ -98,10 +98,29 @@ export const handlePasswordError = async (
const status = error?.response?.status;
// Handle specific error cases with user-friendly messages
// Backend returns 400 with PdfPasswordException for incorrect/missing PDF passwords
if (status === 500) {
// 500 typically means incorrect password for encrypted PDFs
return incorrectPasswordMessage;
}
if (status === 400) {
const data = error?.response?.data;
// ProblemDetail JSON has type "/errors/pdf-password", blob needs parsing
const isPasswordError = await (async () => {
if (data instanceof Blob) {
try {
const text = await data.text();
return text.includes("pdf-password") || text.includes("passworded");
} catch {
return false;
}
}
const type = data?.type ?? "";
return type.includes("pdf-password");
})();
if (isPasswordError) {
return incorrectPasswordMessage;
}
}
// For other errors, try to extract the message
const normalizedData = await normalizeAxiosErrorData(error?.response?.data);