fix(back-end): file error handling
All checks were successful
Build, Test and Deploy / build-and-push (push) Successful in 39s
Build, Test and Deploy / deploy (push) Successful in 8s
Build, Test and Deploy / test-backend (push) Successful in 1m20s

This commit is contained in:
2026-02-16 14:20:31 +01:00
parent 8c82470401
commit 3a5e4e3427
4 changed files with 15 additions and 15 deletions

View File

@@ -23,17 +23,20 @@ public class ClamAVService {
@Value("${clamav.port:3310}") int port
) {
logger.info("Initializing ClamAV client at {}:{}", host, port);
ClamavClient client = null;
try {
this.clamavClient = new ClamavClient(host, port);
client = new ClamavClient(host, port);
} catch (Exception e) {
logger.error("Failed to initialize ClamAV client: " + e.getMessage());
// We don't throw exception here to allow app to start even if ClamAV is down/unreachable
// scan() method will handle null client or failure
throw new RuntimeException("ClamAV initialization failed", e);
}
this.clamavClient = client;
}
public boolean scan(InputStream inputStream) {
if (clamavClient == null) {
logger.warn("ClamAV client not initialized, skipping scan (FAIL-OPEN)");
return true;
}
try {
ScanResult result = clamavClient.scan(inputStream);
if (result instanceof ScanResult.OK) {
@@ -43,15 +46,12 @@ public class ClamAVService {
logger.warn("VIRUS DETECTED: {}", viruses);
return false;
} else {
logger.warn("Unknown scan result: {}", result);
return false;
logger.warn("Unknown scan result: {}. Allowing file (FAIL-OPEN)", result);
return true;
}
} catch (Exception e) {
logger.error("Error scanning file with ClamAV", e);
// Fail safe? Or fail secure?
// Usually if scanner fails, we should probably reject to be safe, or allow with warning depending on policy.
// For now, let's reject to be safe.
return false;
logger.error("Error scanning file with ClamAV. Allowing file (FAIL-OPEN)", e);
return true;
}
}
}

View File

@@ -3,9 +3,9 @@
<p class="subtitle">{{ 'CALC.SUBTITLE' | translate }}</p>
@if (error() === 'VIRUS_DETECTED') {
<app-alert type="error">{{ 'CALC.ERROR_VIRUS' | translate }}</app-alert>
<app-alert type="error">{{ 'CALC.ERROR_VIRUS_DETECTED' | translate }}</app-alert>
} @else if (error()) {
<app-alert type="error">{{ 'CALC.ERROR_GENERIC' | translate }}</app-alert>
<app-alert type="error">{{ 'CALC.ERROR_' + error() | translate }}</app-alert>
}
</div>

View File

@@ -61,7 +61,7 @@
"ORDER": "Order Now",
"CONSULT": "Request Consultation",
"ERROR_GENERIC": "An error occurred while calculating the quote.",
"ERROR_UPLOAD_FAILED": "Calculation failed",
"ERROR_UPLOAD_FAILED": "File upload failed. Please try again.",
"ERROR_VIRUS_DETECTED": "File removed (virus detected)",
"ERROR_SLICING_FAILED": "Slicing error (complex geometry?)",
"NEW_QUOTE": "Calculate New Quote",

View File

@@ -40,7 +40,7 @@
"ORDER": "Ordina Ora",
"CONSULT": "Richiedi Consulenza",
"ERROR_GENERIC": "Si è verificato un errore durante il calcolo del preventivo.",
"ERROR_UPLOAD_FAILED": "Calcolo fallito",
"ERROR_UPLOAD_FAILED": "Caricamento file fallito. Riprova.",
"ERROR_VIRUS_DETECTED": "File rimosso (virus rilevato)",
"ERROR_SLICING_FAILED": "Errore slicing (geometria complessa?)",
"NEW_QUOTE": "Calcola Nuovo Preventivo",