fix: Fehler-Feedback Kreditzuordnung, robustes PDF-Fehlerhandling
Kreditzuordnung im Szenario prueft jetzt response.ok, zeigt bei Fehlschlag eine deutsche Meldung und macht die Checkbox-Aenderung rueckgaengig statt stillschweigend neu zu laden. process_pdf faengt zusaetzlich zu ParserError auch unerwartete Parser-Exceptions (z.B. pdfminer bei strukturell kaputten PDFs) ab und legt dafuer ein sauberes error-Statement an statt eines unbehandelten 500; die Datei bleibt dabei im Posteingang. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,15 @@ def _find_or_create_account(session: Session, bank: str, iban: str | None, filen
|
||||
return acc
|
||||
|
||||
|
||||
def _error_statement(session: Session, filename: str, message: str) -> Statement:
|
||||
stmt = Statement(filename=filename, bank="unbekannt", account_id=None,
|
||||
status="error", error_message=message)
|
||||
session.add(stmt)
|
||||
session.commit()
|
||||
session.refresh(stmt)
|
||||
return stmt
|
||||
|
||||
|
||||
def process_pdf(session: Session, path: Path) -> Statement:
|
||||
settings = get_settings()
|
||||
filename = path.name
|
||||
@@ -30,12 +39,15 @@ def process_pdf(session: Session, path: Path) -> Statement:
|
||||
try:
|
||||
parsed = parse_pdf(path)
|
||||
except ParserError as exc:
|
||||
stmt = Statement(filename=filename, bank="unbekannt", account_id=None,
|
||||
status="error", error_message=str(exc))
|
||||
session.add(stmt)
|
||||
session.commit()
|
||||
session.refresh(stmt)
|
||||
return stmt
|
||||
return _error_statement(session, filename, str(exc))
|
||||
except Exception as exc:
|
||||
# Fremdbibliotheken (pdfplumber/pdfminer) werfen bei strukturell
|
||||
# kaputten PDFs eigene Exception-Typen statt ParserError (z.B.
|
||||
# PdfminerException "No /Root object!"). Ohne diesen Fang wuerde ein
|
||||
# kaputtes Upload zu einem unbehandelten 500 fuehren statt zu einem
|
||||
# sauberen Fehler-Import wie bei "Bank nicht erkannt". Die Datei
|
||||
# bleibt dabei unangetastet im Posteingang.
|
||||
return _error_statement(session, filename, f"PDF nicht lesbar: {exc}")
|
||||
|
||||
account = _find_or_create_account(session, parsed.bank, parsed.iban, filename)
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
{% for l in loans %}
|
||||
<label class="inline-form">
|
||||
<input type="checkbox" {% if l.id in row.assigned_loan_ids %}checked{% endif %}
|
||||
onchange="toggleScenarioLoan({{ sc.id }}, {{ l.id }}, this.checked)">
|
||||
onchange="toggleScenarioLoan({{ sc.id }}, {{ l.id }}, this.checked, this)">
|
||||
{{ l.name }}
|
||||
</label>
|
||||
{% else %}
|
||||
@@ -354,9 +354,18 @@
|
||||
recSelect.disabled = isCategory;
|
||||
}
|
||||
|
||||
function toggleScenarioLoan(scenarioId, loanId, checked) {
|
||||
function toggleScenarioLoan(scenarioId, loanId, checked, checkbox) {
|
||||
fetch('/api/scenarios/' + scenarioId + '/loans/' + loanId, { method: checked ? 'POST' : 'DELETE' })
|
||||
.then(function () { window.location.reload(); });
|
||||
.then(function (resp) {
|
||||
if (!resp.ok) {
|
||||
throw new Error('HTTP ' + resp.status);
|
||||
}
|
||||
window.location.reload();
|
||||
})
|
||||
.catch(function (err) {
|
||||
checkbox.checked = !checked;
|
||||
alert('Zuordnung fehlgeschlagen: ' + err.message);
|
||||
});
|
||||
}
|
||||
|
||||
var loadedSchedules = {};
|
||||
|
||||
Reference in New Issue
Block a user