SDK: Fehler
Jeder fehlgeschlagene Aufruf lehnt mit einem PithyxError ab. Probleme des Daemons kommen unverändert durch; die Codes sdk.* stammen aus der Verbindung zwischen App und Desktop. Jeder Code steht in der Fehlerreferenz.
Beim Build aus den TSDoc-Kommentaren von @pithyx/sdk 1.0.0-rc.9 erzeugt; der Text unter den Überschriften ist der Kommentar im Quelltext und bleibt Englisch.
Klassen
Abschnitt betitelt „Klassen“PithyxError
Abschnitt betitelt „PithyxError“The error every failed SDK call rejects with. It carries the problem’s fields, so an app branches on code and
translates it itself; message is the English detail, or the code when there is none.
Beispiel
Abschnitt betitelt „Beispiel“try { await app.storage.set('draft', draft);} catch (error) { if (error instanceof PithyxError && error.code === 'app.storage.too_large') { showTooLarge(); } else { await app.ui.showError(error); }}Erweitert
Abschnitt betitelt „Erweitert“Error
Implementiert
Abschnitt betitelt „Implementiert“Konstruktoren
Abschnitt betitelt „Konstruktoren“Konstruktor
Abschnitt betitelt „Konstruktor“new PithyxError(problem): PithyxError;An error from a problem, as the SDK builds it from a desktop or daemon answer.
Parameter
Abschnitt betitelt „Parameter“| Parameter | Typ | Beschreibung |
|---|---|---|
problem |
Problem |
The problem’s code, params, detail and request id. |
Rückgabewert
Abschnitt betitelt „Rückgabewert“Überschreibt
Abschnitt betitelt „Überschreibt“Error.constructor;Eigenschaften
Abschnitt betitelt „Eigenschaften“readonly code: string;Stable code, area.object.reason, for example fs.entry.not_found.
Implementierung von
Abschnitt betitelt „Implementierung von“readonly params: Record<string, unknown>;Values for the translated message, for example { permission: 'files.read' }.
Implementierung von
Abschnitt betitelt „Implementierung von“detail?
Abschnitt betitelt „detail?“readonly optional detail?: string;English fallback text.
Implementierung von
Abschnitt betitelt „Implementierung von“requestId?
Abschnitt betitelt „requestId?“readonly optional requestId?: string;The request id for support, when the daemon was involved.
Implementierung von
Abschnitt betitelt „Implementierung von“Methoden
Abschnitt betitelt „Methoden“toProblem()
Abschnitt betitelt „toProblem()“toProblem(): Problem;The plain problem, for sending it over a transport.
Rückgabewert
Abschnitt betitelt „Rückgabewert“The problem without the Error parts.
Schnittstellen
Abschnitt betitelt „Schnittstellen“Problem
Abschnitt betitelt „Problem“A problem as it travels between desktop and app: RFC 9457 fields the Pithyx API uses.
Eigenschaften
Abschnitt betitelt „Eigenschaften“code: string;Stable code, area.object.reason.
params: Record<string, unknown>;Values for the translated message.
detail?
Abschnitt betitelt „detail?“optional detail?: string;English fallback text.
requestId?
Abschnitt betitelt „requestId?“optional requestId?: string;The request id for support, when the daemon was involved.
Typenaliasse
Abschnitt betitelt „Typenaliasse“SdkErrorCode
Abschnitt betitelt „SdkErrorCode“type SdkErrorCode = (typeof sdkErrorCodes)[number];A code of the SDK’s own transport errors, translated under errors.sdk.*.
Variablen
Abschnitt betitelt „Variablen“sdkErrorCodes
Abschnitt betitelt „sdkErrorCodes“const sdkErrorCodes: readonly [ 'sdk.method.unknown', 'sdk.request.invalid', 'sdk.request.timeout', 'sdk.transport.closed', 'sdk.protocol.unsupported', 'sdk.transfer.cancelled', 'sdk.backend.endpoint_unknown', 'sdk.backend.unreachable',];Codes the SDK itself can produce. Codes of the daemon API come through unchanged and are strings as well.
Funktionen
Abschnitt betitelt „Funktionen“isProblem()
Abschnitt betitelt „isProblem()“function isProblem(value): value is Problem;Whether a value has the shape of a problem (RFC 9457 fields code and params).
Parameter
Abschnitt betitelt „Parameter“| Parameter | Typ | Beschreibung |
|---|---|---|
value |
unknown |
Anything, for example a caught error or a parsed response body. |
Rückgabewert
Abschnitt betitelt „Rückgabewert“value is Problem
Whether value.code is a string and value.params an object.