renames + rewriting docs

This commit is contained in:
Timo K.
2026-10-08 13:53:56 +02:00
parent 1a999eaa54
commit 61e353d919
15 changed files with 1061 additions and 117 deletions
+10 -10
View File
@@ -7,29 +7,29 @@ Please see LICENSE in the repository root for full details.
import { describe, expect, it } from "vitest";
import { RtcSessionError } from "../api";
import { toRtcSessionError } from "./errors";
import { MatrixRTCError } from "../api";
import { toMatrixRTCError } from "./errors";
describe("toRtcSessionError", () => {
it("keeps an RtcSessionError as it is", () => {
const error = new RtcSessionError("gone");
expect(toRtcSessionError(error)).toBe(error);
describe("toMatrixRTCError", () => {
it("keeps an MatrixRTCError as it is", () => {
const error = new MatrixRTCError("gone");
expect(toMatrixRTCError(error)).toBe(error);
});
it("wraps another error as the cause", () => {
const cause = new Error("boom");
const error = toRtcSessionError(cause);
expect(error).toBeInstanceOf(RtcSessionError);
const error = toMatrixRTCError(cause);
expect(error).toBeInstanceOf(MatrixRTCError);
expect(error.message).toBe("boom");
expect(error.cause).toBe(cause);
});
it("falls back to the code of an error without a message", () => {
const cause = Object.assign(new Error(""), { code: "SFU_ERROR" });
expect(toRtcSessionError(cause).message).toBe("SFU_ERROR");
expect(toMatrixRTCError(cause).message).toBe("SFU_ERROR");
});
it("stringifies anything else", () => {
expect(toRtcSessionError("nope").message).toBe("nope");
expect(toMatrixRTCError("nope").message).toBe("nope");
});
});
+5 -5
View File
@@ -5,14 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { RtcSessionError } from "../api";
import { MatrixRTCError } from "../api";
/** Wraps whatever a backend threw into the SDK's error type, keeping it as the cause. */
export function toRtcSessionError(error: unknown): RtcSessionError {
if (error instanceof RtcSessionError) return error;
export function toMatrixRTCError(error: unknown): MatrixRTCError {
if (error instanceof MatrixRTCError) return error;
if (error instanceof Error)
return new RtcSessionError(messageOf(error), { cause: error });
return new RtcSessionError(String(error));
return new MatrixRTCError(messageOf(error), { cause: error });
return new MatrixRTCError(String(error));
}
/**