Enhance security and error handling in various components by refining error catch blocks to ignore specific errors, improving code clarity and consistency across the application.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Clean Code: Single Responsibility Principle
|
||||
*/
|
||||
|
||||
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib'
|
||||
import { StandardFonts } from 'pdf-lib'
|
||||
import { mapFieldValue, shouldCheckField, shouldCheckByValue } from './pdf-field-mapper.js'
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export function setTextFieldIfEmpty(field, value) {
|
||||
return // Field already has content, don't overwrite
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Ignore getter errors and proceed to set
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ export function setCheckboxIfNeeded(field, fieldName, data) {
|
||||
if (!(typeof field.isChecked === 'function' && field.isChecked())) {
|
||||
field.check && field.check()
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
field.check && field.check()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ export async function fillFormFields(pdfDoc, form, data) {
|
||||
try {
|
||||
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
form.updateFieldAppearances(helveticaFont)
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
console.warn('Could not update field appearances:', error.message)
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ export async function fillPdfForm(pdfDoc, form, data) {
|
||||
|
||||
// Check if PLZ/Ort field on page 1 is empty and fix it
|
||||
await fixPLZOrtField(pdfDoc, data)
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
console.warn('Form filling failed, using fallback:', error.message)
|
||||
await fillFormFieldsPositionally(pdfDoc, data)
|
||||
}
|
||||
@@ -137,8 +137,7 @@ export async function fillPdfForm(pdfDoc, form, data) {
|
||||
async function fixPLZOrtField(pdfDoc, data) {
|
||||
try {
|
||||
const pages = pdfDoc.getPages()
|
||||
const firstPage = pages[0]
|
||||
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
await pdfDoc.embedFont(StandardFonts.Helvetica)
|
||||
|
||||
// Draw PLZ/Ort at the correct position on page 1
|
||||
const plzOrtText = `${data.plz || ''} ${data.ort || ''}`.trim()
|
||||
@@ -161,7 +160,7 @@ async function fixPLZOrtField(pdfDoc, data) {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
console.warn('Could not fix PLZ/Ort field:', error.message)
|
||||
}
|
||||
}
|
||||
@@ -222,7 +221,7 @@ async function fillFormFieldsPositionally(pdfDoc, data) {
|
||||
firstPage.drawText('X', { x: 116, y: -8, size: 12, font: helveticaFont })
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
console.error('Positional filling failed:', error.message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user