Nextcloud: Netzfehler mit Ursache melden (0.44.4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
Claude
2026-11-04 21:26:50 +00:00
parent 7e18b7f4de
commit 18e05b5634
6 changed files with 42 additions and 5 deletions

View File

@@ -2,6 +2,10 @@
Neueste Version oben. Erste Zahl: großer Umbau, zweite: neue Funktionen, dritte: Fehlerbehebungen. Neueste Version oben. Erste Zahl: großer Umbau, zweite: neue Funktionen, dritte: Fehlerbehebungen.
## 0.44.4 (04.11.2026)
- Nextcloud: Ist die Nextcloud nicht erreichbar, nennt die Meldung jetzt die Ursache (z. B. Zertifikat, DNS, Verbindung abgelehnt) statt nur „fetch failed“. Gilt für Verbindung prüfen, Projektordner, Ablage und Kontakte-Abgleich.
## 0.44.3 (04.11.2026) ## 0.44.3 (04.11.2026)
- Server: vorerst nur die Produktion, ohne Testumgebung. Daten in Ordnern statt Docker-Volumes: `deploy/data/db` (Datenbank) und `deploy/data/backup` (Sicherungen). `update.sh` kopiert vorhandene Daten aus den bisherigen Volumes einmalig herüber. Aufruf jetzt `./update.sh <version>` und `./zurueck.sh`. - Server: vorerst nur die Produktion, ohne Testumgebung. Daten in Ordnern statt Docker-Volumes: `deploy/data/db` (Datenbank) und `deploy/data/backup` (Sicherungen). `update.sh` kopiert vorhandene Daten aus den bisherigen Volumes einmalig herüber. Aufruf jetzt `./update.sh <version>` und `./zurueck.sh`.

View File

@@ -1,6 +1,6 @@
{ {
"name": "betrieb", "name": "betrieb",
"version": "0.44.3", "version": "0.44.4",
"private": true, "private": true,
"description": "Betriebsführungsprogramm Schaarschmidt Holzbau", "description": "Betriebsführungsprogramm Schaarschmidt Holzbau",
"type": "module", "type": "module",

View File

@@ -11,7 +11,7 @@ import { legeZahlungsplanAn, restNachziehen, zahlungsplanFest, zahlungsplaeneAut
import { uebersicht } from "./uebersicht.js"; import { uebersicht } from "./uebersicht.js";
import { aufgabenKalender, baustellenKalender } from "./kalender.js"; import { aufgabenKalender, baustellenKalender } from "./kalender.js";
import { nummernAufraeumen, projektNummerVorbereiten } from "./nummern.js"; import { nummernAufraeumen, projektNummerVorbereiten } from "./nummern.js";
import { Nextcloud, STATUSORDNER, ordnerAbgleichen, webdavBasis } from "./nextcloud.js"; import { Nextcloud, STATUSORDNER, fehlerText, ordnerAbgleichen, webdavBasis } from "./nextcloud.js";
import { CardDav, ergebnisText, kontakteAbgleichen, vcfEinlesen } from "./kontaktabgleich.js"; import { CardDav, ergebnisText, kontakteAbgleichen, vcfEinlesen } from "./kontaktabgleich.js";
import { NUR_SICHERUNG, TABELLEN } from "./tabellen.js"; import { NUR_SICHERUNG, TABELLEN } from "./tabellen.js";
import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js"; import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js";

View File

@@ -4,7 +4,7 @@
import type { Client, Pool } from "./db.js"; import type { Client, Pool } from "./db.js";
import { transaktion } from "./db.js"; import { transaktion } from "./db.js";
import type { NextcloudZugang } from "./nextcloud.js"; import { type NextcloudZugang, abrufMitUrsache } from "./nextcloud.js";
import { FELDER, type KontaktFelder, felderAus, fingerabdruck, karteMit, kartenAus, nummer, revVon, uidVon } from "../domain/vcard.js"; import { FELDER, type KontaktFelder, felderAus, fingerabdruck, karteMit, kartenAus, nummer, revVon, uidVon } from "../domain/vcard.js";
export interface Adressbuch { href: string; name: string } export interface Adressbuch { href: string; name: string }
@@ -27,7 +27,7 @@ export class CardDav {
} }
private anfrage(methode: string, href: string, kopf: Record<string, string> = {}, body?: string): Promise<Response> { private anfrage(methode: string, href: string, kopf: Record<string, string> = {}, body?: string): Promise<Response> {
return this.abruf(this.origin + href, { return abrufMitUrsache(this.abruf, this.origin + href, {
method: methode, method: methode,
headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf }, headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf },
body, body,

View File

@@ -49,6 +49,28 @@ export function webdavBasis(z: { adresse: string; benutzer: string; ordner: stri
return teile.length ? `${a}/${teile.map(encodeURIComponent).join("/")}` : a; return teile.length ? `${a}/${teile.map(encodeURIComponent).join("/")}` : a;
} }
/**
* Fehlertext mit Ursache: „fetch failed“ allein sagt nichts; die Ursache (z. B. Zertifikat, DNS, Verbindung abgelehnt)
* steckt in err.cause mit code und message.
*/
export function fehlerText(err: unknown): string {
const teile: string[] = [];
for (let e = err as { message?: string; code?: string; cause?: unknown } | undefined, n = 0; e && n < 4; e = e.cause as typeof e, n++) {
const t = [e.code, e.message].filter(Boolean).join(": ");
if (t && !teile.includes(t)) teile.push(t);
}
return teile.join(" – ") || String(err);
}
/** Netzfehler mit Ziel und Ursache weiterreichen */
export async function abrufMitUrsache(abruf: typeof fetch, adresse: string, init: RequestInit): Promise<Response> {
try {
return await abruf(adresse, init);
} catch (err) {
throw new Error(`${new URL(adresse).host} nicht erreichbar: ${fehlerText(err)}`, { cause: err });
}
}
const kodiert = (pfad: string) => pfad.split("/").map(encodeURIComponent).join("/"); const kodiert = (pfad: string) => pfad.split("/").map(encodeURIComponent).join("/");
export class Nextcloud { export class Nextcloud {
@@ -59,7 +81,7 @@ export class Nextcloud {
} }
private async anfrage(methode: string, pfad: string, kopf: Record<string, string> = {}, body?: string): Promise<Response> { private async anfrage(methode: string, pfad: string, kopf: Record<string, string> = {}, body?: string): Promise<Response> {
return this.abruf(this.adresse(pfad), { return abrufMitUrsache(this.abruf, this.adresse(pfad), {
method: methode, method: methode,
headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf }, headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf },
body, body,

View File

@@ -65,3 +65,14 @@ describe("vCard", () => {
expect(fingerabdruck({ name: "A B" })).toBe(fingerabdruck({ name: "A B", firma: null })); expect(fingerabdruck({ name: "A B" })).toBe(fingerabdruck({ name: "A B", firma: null }));
}); });
}); });
describe("Netzfehler mit Ursache", () => {
it("zeigt code und message aus err.cause", async () => {
const { abrufMitUrsache, fehlerText } = await import("../src/server/nextcloud.js");
const tls = Object.assign(new Error("unable to verify the first certificate"), { code: "UNABLE_TO_VERIFY_LEAF_SIGNATURE" });
const fehler = new TypeError("fetch failed", { cause: tls });
expect(fehlerText(fehler)).toBe("fetch failed – UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate");
const abruf = (async () => { throw fehler; }) as unknown as typeof fetch;
await expect(abrufMitUrsache(abruf, "https://cloud.test/remote.php/dav", {})).rejects.toThrow("cloud.test nicht erreichbar: fetch failed – UNABLE_TO_VERIFY_LEAF_SIGNATURE");
});
});