mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
renames + rewriting docs
This commit is contained in:
@@ -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,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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user