mirror of
https://github.com/vector-im/element-call.git
synced 2026-01-30 03:15:55 +00:00
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 { useActiveLivekitFocus } from "../room/useActiveFocus";
|
||||
import { useGroupCallErrorBoundary } from "../room/useCallErrorBoundary.ts";
|
||||
import { FailToGetOpenIdToken } from "../utils/errors.ts";
|
||||
import { doNetworkOperationWithRetry } from "../utils/matrix.ts";
|
||||
import { useErrorBoundary } from "../useErrorBoundary";
|
||||
import { FailToGetOpenIdToken } from "../utils/errors";
|
||||
import { doNetworkOperationWithRetry } from "../utils/matrix";
|
||||
|
||||
export interface SFUConfig {
|
||||
url: string;
|
||||
@@ -41,7 +41,7 @@ export function useOpenIDSFU(
|
||||
const [sfuConfig, setSFUConfig] = useState<SFUConfig | undefined>(undefined);
|
||||
|
||||
const activeFocus = useActiveLivekitFocus(rtcSession);
|
||||
const { showGroupCallErrorBoundary } = useGroupCallErrorBoundary();
|
||||
const { showErrorBoundary } = useErrorBoundary();
|
||||
|
||||
useEffect(() => {
|
||||
if (activeFocus) {
|
||||
@@ -50,14 +50,14 @@ export function useOpenIDSFU(
|
||||
setSFUConfig(sfuConfig);
|
||||
},
|
||||
(e) => {
|
||||
showGroupCallErrorBoundary(new FailToGetOpenIdToken(e));
|
||||
showErrorBoundary(new FailToGetOpenIdToken(e));
|
||||
logger.error("Failed to get SFU config", e);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
setSFUConfig(undefined);
|
||||
}
|
||||
}, [client, activeFocus, showGroupCallErrorBoundary]);
|
||||
}, [client, activeFocus, showErrorBoundary]);
|
||||
|
||||
return sfuConfig;
|
||||
}
|
||||
|
||||
@@ -11,19 +11,19 @@ import { type ReactElement, useCallback } from "react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
|
||||
import { GroupCallErrorBoundary } from "./GroupCallErrorBoundary.tsx";
|
||||
import { useGroupCallErrorBoundary } from "./useCallErrorBoundary.ts";
|
||||
import { ConnectionLostError } from "../utils/errors.ts";
|
||||
import { GroupCallErrorBoundary } from "./room/GroupCallErrorBoundary";
|
||||
import { useErrorBoundary } from "./useErrorBoundary";
|
||||
import { ConnectionLostError } from "./utils/errors";
|
||||
|
||||
it("should show async error", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
const TestComponent = (): ReactElement => {
|
||||
const { showGroupCallErrorBoundary } = useGroupCallErrorBoundary();
|
||||
const { showErrorBoundary } = useErrorBoundary();
|
||||
|
||||
const onClick = useCallback((): void => {
|
||||
showGroupCallErrorBoundary(new ConnectionLostError());
|
||||
}, [showGroupCallErrorBoundary]);
|
||||
showErrorBoundary(new ConnectionLostError());
|
||||
}, [showErrorBoundary]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -7,18 +7,16 @@ Please see LICENSE in the repository root for full details.
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import type { ElementCallError } from "../utils/errors.ts";
|
||||
|
||||
export type UseErrorBoundaryApi = {
|
||||
showGroupCallErrorBoundary: (error: ElementCallError) => void;
|
||||
showErrorBoundary: (error: Error) => void;
|
||||
};
|
||||
|
||||
export function useGroupCallErrorBoundary(): UseErrorBoundaryApi {
|
||||
const [error, setError] = useState<ElementCallError | null>(null);
|
||||
export function useErrorBoundary(): UseErrorBoundaryApi {
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const memoized: UseErrorBoundaryApi = useMemo(
|
||||
() => ({
|
||||
showGroupCallErrorBoundary: (error: ElementCallError) => setError(error),
|
||||
showErrorBoundary: (error: Error) => setError(error),
|
||||
}),
|
||||
[],
|
||||
);
|
||||
Reference in New Issue
Block a user