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:
@@ -11,7 +11,7 @@ import { legeZahlungsplanAn, restNachziehen, zahlungsplanFest, zahlungsplaeneAut
|
||||
import { uebersicht } from "./uebersicht.js";
|
||||
import { aufgabenKalender, baustellenKalender } from "./kalender.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 { NUR_SICHERUNG, TABELLEN } from "./tabellen.js";
|
||||
import { EinstellungenSchema, type Einstellungen } from "./einstellungen.js";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import type { Client, Pool } 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";
|
||||
|
||||
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> {
|
||||
return this.abruf(this.origin + href, {
|
||||
return abrufMitUrsache(this.abruf, this.origin + href, {
|
||||
method: methode,
|
||||
headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf },
|
||||
body,
|
||||
|
||||
@@ -49,6 +49,28 @@ export function webdavBasis(z: { adresse: string; benutzer: string; ordner: stri
|
||||
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("/");
|
||||
|
||||
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> {
|
||||
return this.abruf(this.adresse(pfad), {
|
||||
return abrufMitUrsache(this.abruf, this.adresse(pfad), {
|
||||
method: methode,
|
||||
headers: { authorization: `Basic ${btoa(`${this.z.benutzer}:${this.z.passwort}`)}`, ...kopf },
|
||||
body,
|
||||
|
||||
Reference in New Issue
Block a user