Rename error boundary hook
It doesn't check whether it's actually used inside a GroupCallErrorBoundary, and it's generally useful for interacting with any error boundary, so I'm giving it a generic name to reflect this.
This commit is contained in:
@@ -12,9 +12,9 @@ import { useEffect, useState } from "react";
|
|||||||
import { type LivekitFocus } from "matrix-js-sdk/src/matrixrtc/LivekitFocus";
|
import { type LivekitFocus } from "matrix-js-sdk/src/matrixrtc/LivekitFocus";
|
||||||
|
|
||||||
import { useActiveLivekitFocus } from "../room/useActiveFocus";
|
import { useActiveLivekitFocus } from "../room/useActiveFocus";
|
||||||
import { useGroupCallErrorBoundary } from "../room/useCallErrorBoundary.ts";
|
import { useErrorBoundary } from "../useErrorBoundary";
|
||||||
import { FailToGetOpenIdToken } from "../utils/errors.ts";
|
import { FailToGetOpenIdToken } from "../utils/errors";
|
||||||
import { doNetworkOperationWithRetry } from "../utils/matrix.ts";
|
import { doNetworkOperationWithRetry } from "../utils/matrix";
|
||||||
|
|
||||||
export interface SFUConfig {
|
export interface SFUConfig {
|
||||||
url: string;
|
url: string;
|
||||||
@@ -41,7 +41,7 @@ export function useOpenIDSFU(
|
|||||||
const [sfuConfig, setSFUConfig] = useState<SFUConfig | undefined>(undefined);
|
const [sfuConfig, setSFUConfig] = useState<SFUConfig | undefined>(undefined);
|
||||||
|
|
||||||
const activeFocus = useActiveLivekitFocus(rtcSession);
|
const activeFocus = useActiveLivekitFocus(rtcSession);
|
||||||
const { showGroupCallErrorBoundary } = useGroupCallErrorBoundary();
|
const { showErrorBoundary } = useErrorBoundary();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeFocus) {
|
if (activeFocus) {
|
||||||
@@ -50,14 +50,14 @@ export function useOpenIDSFU(
|
|||||||
setSFUConfig(sfuConfig);
|
setSFUConfig(sfuConfig);
|
||||||
},
|
},
|
||||||
(e) => {
|
(e) => {
|
||||||
showGroupCallErrorBoundary(new FailToGetOpenIdToken(e));
|
showErrorBoundary(new FailToGetOpenIdToken(e));
|
||||||
logger.error("Failed to get SFU config", e);
|
logger.error("Failed to get SFU config", e);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setSFUConfig(undefined);
|
setSFUConfig(undefined);
|
||||||
}
|
}
|
||||||
}, [client, activeFocus, showGroupCallErrorBoundary]);
|
}, [client, activeFocus, showErrorBoundary]);
|
||||||
|
|
||||||
return sfuConfig;
|
return sfuConfig;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ import { type ReactElement, useCallback } from "react";
|
|||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { BrowserRouter } from "react-router-dom";
|
import { BrowserRouter } from "react-router-dom";
|
||||||
|
|
||||||
import { GroupCallErrorBoundary } from "./GroupCallErrorBoundary.tsx";
|
import { GroupCallErrorBoundary } from "./room/GroupCallErrorBoundary";
|
||||||
import { useGroupCallErrorBoundary } from "./useCallErrorBoundary.ts";
|
import { useErrorBoundary } from "./useErrorBoundary";
|
||||||
import { ConnectionLostError } from "../utils/errors.ts";
|
import { ConnectionLostError } from "./utils/errors";
|
||||||
|
|
||||||
it("should show async error", async () => {
|
it("should show async error", async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
|
|
||||||
const TestComponent = (): ReactElement => {
|
const TestComponent = (): ReactElement => {
|
||||||
const { showGroupCallErrorBoundary } = useGroupCallErrorBoundary();
|
const { showErrorBoundary } = useErrorBoundary();
|
||||||
|
|
||||||
const onClick = useCallback((): void => {
|
const onClick = useCallback((): void => {
|
||||||
showGroupCallErrorBoundary(new ConnectionLostError());
|
showErrorBoundary(new ConnectionLostError());
|
||||||
}, [showGroupCallErrorBoundary]);
|
}, [showErrorBoundary]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -7,18 +7,16 @@ Please see LICENSE in the repository root for full details.
|
|||||||
|
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
import type { ElementCallError } from "../utils/errors.ts";
|
|
||||||
|
|
||||||
export type UseErrorBoundaryApi = {
|
export type UseErrorBoundaryApi = {
|
||||||
showGroupCallErrorBoundary: (error: ElementCallError) => void;
|
showErrorBoundary: (error: Error) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useGroupCallErrorBoundary(): UseErrorBoundaryApi {
|
export function useErrorBoundary(): UseErrorBoundaryApi {
|
||||||
const [error, setError] = useState<ElementCallError | null>(null);
|
const [error, setError] = useState<Error | null>(null);
|
||||||
|
|
||||||
const memoized: UseErrorBoundaryApi = useMemo(
|
const memoized: UseErrorBoundaryApi = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
showGroupCallErrorBoundary: (error: ElementCallError) => setError(error),
|
showErrorBoundary: (error: Error) => setError(error),
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
Reference in New Issue
Block a user