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:
@@ -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