Eingangsrechnungen: Fehlergrund von update.php weitergeben

update.php antwortet bei Validierungsfehlern mit HTTP 422 und nennt den
Grund im Body. Bisher warf Axios dabei nur "Request failed with status
code 422". Jetzt werden 4xx-Antworten ausgewertet und msg bzw. der Body
in die Fehlermeldung uebernommen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bjoernpoettkerandClaude Opus 5.5 committed 2026-09-27 15:22:21 +02:00
1 parent 0a01fbe8ca
commit f54a0fe155
5 files changed
+47 -12

No files matched your search

+10 -4
View File
@@ -347,7 +347,8 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
Referer: `${this.baseUrl}/eingangsrechnungen/detail/${rechnungId}`,
Origin: this.baseUrl,
},
validateStatus: status => status >= 200 && status < 400,
// 4xx nicht als Axios-Fehler werfen: Agrarmonitor schickt den Grund (z. B. bei 422) im Body.
validateStatus: status => status >= 200 && status < 500,
}
);
@@ -355,11 +356,16 @@ export class AgrarmonitorConnector implements AgrarmonitorConnectorResult {
// Erfolg: leeres Array. Fehler: Objekt mit msg.
const msg = (response.data as { msg?: unknown } | null)?.msg;
if (typeof msg === 'string' && msg.trim()) {
throw new Error(`Rechnung ${rechnungId} konnte nicht gespeichert werden: ${msg.trim()}`);
const ok = response.status >= 200 && response.status < 300;
if ((typeof msg === 'string' && msg.trim()) || !ok) {
const grund =
typeof msg === 'string' && msg.trim()
? msg.trim()
: (typeof response.data === 'string' ? response.data : JSON.stringify(response.data)).slice(0, 500);
throw new Error(`Rechnung ${rechnungId} konnte nicht gespeichert werden (HTTP ${response.status}): ${grund}`);
}
return response.status >= 200 && response.status < 300;
return true;
}
async setLieferscheinNummer(rechnungId: number, nummer: string): Promise<void> {