review: Improve error structure + better RTCFocus error message

This commit is contained in:
Valere
2025-02-27 09:26:38 +01:00
parent 109809182f
commit 2ba803fcef
5 changed files with 81 additions and 23 deletions

View File

@@ -5,29 +5,68 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { t } from "i18next";
export enum ErrorCode {
/**
* Configuration problem due to no MatrixRTC backend/SFU is exposed via .well-known and no fallback configured.
*/
MISSING_LIVE_KIT_SERVICE_URL = "MISSING_LIVE_KIT_SERVICE_URL",
MISSING_MATRIX_RTC_FOCUS = "MISSING_MATRIX_RTC_FOCUS",
CONNECTION_LOST_ERROR = "CONNECTION_LOST_ERROR",
// UNKNOWN_ERROR = "UNKNOWN_ERROR",
}
export enum ErrorCategory {
/** Calling is not supported, server miss-configured (JWT service missing, no MSC support ...)*/
CONFIGURATION_ISSUE = "CONFIGURATION_ISSUE",
NETWORK_CONNECTIVITY = "NETWORK_CONNECTIVITY",
// SYSTEM_FAILURE / FEDERATION_FAILURE ..
}
/**
* Structure for errors that occur when using ElementCall.
*/
export class ElementCallError extends Error {
public code: ErrorCode;
public category: ErrorCategory;
public localisedMessage?: string;
public constructor(message: string, code: ErrorCode) {
super(message);
public constructor(
name: string,
code: ErrorCode,
category: ErrorCategory,
localisedMessage?: string,
) {
super();
this.localisedMessage = localisedMessage;
this.category = category;
this.code = code;
}
}
export class MatrixRTCFocusMissingError extends ElementCallError {
public domain: string;
public constructor(domain: string) {
super(
"MatrixRTCFocusMissingError",
ErrorCode.MISSING_MATRIX_RTC_FOCUS,
ErrorCategory.CONFIGURATION_ISSUE,
t("error.matrix_rtc_focus_missing", {
brand: domain,
errorCode: ErrorCode.MISSING_MATRIX_RTC_FOCUS,
}),
);
this.domain = domain;
}
}
export class ConnectionLostError extends ElementCallError {
public constructor() {
super("Connection lost", ErrorCode.CONNECTION_LOST_ERROR);
super(
"Connection lost",
ErrorCode.CONNECTION_LOST_ERROR,
ErrorCategory.NETWORK_CONNECTIVITY,
);
}
}