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.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 4m10s

This commit is contained in:
Torsten Schulz (local)
2025-12-20 15:05:49 +01:00
parent c9037fec45
commit 6fda6ebad0
42 changed files with 117 additions and 113 deletions

View File

@@ -63,7 +63,7 @@ function isEncrypted(data) {
return false
}
return false
} catch (e) {
} catch {
// JSON parsing failed - likely encrypted base64
return true
}
@@ -86,7 +86,7 @@ export async function readUsers() {
try {
users = JSON.parse(data)
console.warn('Entschlüsselung fehlgeschlagen, versuche als unverschlüsseltes Format zu lesen')
} catch (parseError) {
} catch (_parseError) {
console.error('Konnte Benutzerdaten weder entschlüsseln noch als JSON lesen')
return []
}
@@ -117,7 +117,7 @@ export async function readUsers() {
}
return users
} catch (error) {
} catch (_error) {
if (error.code === 'ENOENT') {
return []
}
@@ -133,7 +133,7 @@ export async function writeUsers(users) {
const encryptedData = encryptObject(users, encryptionKey)
await fs.writeFile(USERS_FILE, encryptedData, 'utf-8')
return true
} catch (error) {
} catch (_error) {
console.error('Fehler beim Schreiben der Benutzerdaten:', error)
return false
}
@@ -171,7 +171,7 @@ export async function readSessions() {
const plainData = JSON.parse(data)
console.warn('Entschlüsselung fehlgeschlagen, versuche als unverschlüsseltes Format zu lesen')
return plainData
} catch (parseError) {
} catch (_parseError) {
console.error('Konnte Sessions weder entschlüsseln noch als JSON lesen')
return []
}
@@ -183,7 +183,7 @@ export async function readSessions() {
await writeSessions(sessions)
return sessions
}
} catch (error) {
} catch (_error) {
if (error.code === 'ENOENT') {
return []
}
@@ -199,7 +199,7 @@ export async function writeSessions(sessions) {
const encryptedData = encryptObject(sessions, encryptionKey)
await fs.writeFile(SESSIONS_FILE, encryptedData, 'utf-8')
return true
} catch (error) {
} catch (_error) {
console.error('Fehler beim Schreiben der Sessions:', error)
return false
}
@@ -237,7 +237,7 @@ export function generateToken(user) {
export function verifyToken(token) {
try {
return jwt.verify(token, JWT_SECRET)
} catch (error) {
} catch (_error) {
return null
}
}

View File

@@ -41,7 +41,7 @@ function isEncrypted(data) {
return false
}
return false
} catch (e) {
} catch (_e) {
// JSON parsing failed - likely encrypted base64
return true
}
@@ -67,7 +67,7 @@ export async function readMembers() {
const plainData = JSON.parse(data)
console.warn('Entschlüsselung fehlgeschlagen, versuche als unverschlüsseltes Format zu lesen')
return plainData
} catch (parseError) {
} catch (_parseError) {
console.error('Konnte Mitgliederdaten weder entschlüsseln noch als JSON lesen')
return []
}
@@ -118,7 +118,7 @@ export function normalizeDate(dateString) {
const date = new Date(dateString)
if (isNaN(date.getTime())) return dateString.trim()
return date.toISOString().split('T')[0]
} catch (e) {
} catch (_e) {
return dateString.trim()
}
}

View File

@@ -34,7 +34,7 @@ function isEncrypted(data) {
return false
}
return false
} catch (e) {
} catch (_e) {
return true
}
}
@@ -54,7 +54,7 @@ export async function readSubscribers() {
const plainData = JSON.parse(data)
console.warn('Entschlüsselung fehlgeschlagen, versuche als unverschlüsseltes Format zu lesen')
return plainData
} catch (parseError) {
} catch (_parseError) {
console.error('Konnte Newsletter-Abonnenten weder entschlüsseln noch als JSON lesen')
return []
}

View File

@@ -17,7 +17,7 @@ function formatDateWithLeadingZeros(dateString) {
const month = String(date.getMonth() + 1).padStart(2, '0')
const year = date.getFullYear()
return `${day}.${month}.${year}`
} catch (error) {
} catch (_error) {
return dateString
}
}

View File

@@ -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)
}
}

View File

@@ -54,7 +54,7 @@ export class PDFGeneratorService {
const pdfBytes = await pdfDoc.save()
return new PDFGenerationResult(true, Buffer.from(pdfBytes), filename)
} catch (error) {
} catch (_error) {
console.error('Template PDF generation failed:', error.message)
return new PDFGenerationResult(false, null, null, error.message)
}
@@ -69,11 +69,11 @@ export class PDFGeneratorService {
try {
await fs.access(this.templatePath)
return this.templatePath
} catch (error) {
} catch (_error) {
try {
await fs.access(this.fallbackTemplatePath)
return this.fallbackTemplatePath
} catch (fallbackError) {
} catch (_fallbackError) {
throw new Error('No PDF template found')
}
}
@@ -86,7 +86,6 @@ export class PDFGeneratorService {
*/
generateFilename(data) {
const timestamp = Date.now()
const name = `${data.nachname || 'Unbekannt'}_${data.vorname || 'Unbekannt'}`
return `beitrittserklärung_${timestamp}.pdf`
}