From 9dd540d91e042a628d8c8f2d00eb34f52b89d0fd Mon Sep 17 00:00:00 2001 From: Robin Date: Sun, 19 Jan 2025 21:11:58 -0500 Subject: [PATCH] Count 404 as a connection failure --- locales/en/app.json | 2 +- src/RichError.tsx | 15 ++++++++++++--- src/livekit/openIDSFU.test.ts | 15 ++++++++++++++- src/livekit/openIDSFU.ts | 8 +++++++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/locales/en/app.json b/locales/en/app.json index cbb001da..7552e4b9 100644 --- a/locales/en/app.json +++ b/locales/en/app.json @@ -73,7 +73,7 @@ "disconnected_banner": "Connectivity to the server has been lost.", "error": { "auth_connection_failed_details": "<0>The application could not reach the call authentication service at <2>{{url}}. If you are the server admin, check the network logs and make sure <5>lk-jwt-service is listening at that address.", - "auth_connection_rejected_details": "<0>The application connected to the call authentication service at <2>{{url}}, but it responded with status code {{status}}. If you are the server admin, make sure <8>lk-jwt-service is listening at that address and check the logs for more information.", + "auth_connection_rejected_details": "<0>The application connected to the call authentication service at <2>{{url}}, but it responded with status code {{status}} ({{response}}). If you are the server admin, make sure <10>lk-jwt-service is listening at that address and check the logs for more information.", "call_not_found": "Call not found", "call_not_found_description": "<0>That link doesn't appear to belong to any existing call. Check that you have the right link, or <1>create a new one.", "connection_failed": "Connection failed", diff --git a/src/RichError.tsx b/src/RichError.tsx index 54076838..e5b01515 100644 --- a/src/RichError.tsx +++ b/src/RichError.tsx @@ -102,7 +102,7 @@ const AuthConnectionFailed: FC = ({ }; export class AuthConnectionFailedError extends RichError { - public constructor(livekitServiceUrl: string, cause: unknown) { + public constructor(livekitServiceUrl: string, cause?: unknown) { super( `Failed to connect to ${livekitServiceUrl}`, , @@ -114,11 +114,13 @@ export class AuthConnectionFailedError extends RichError { interface AuthConnectionRejectedProps { livekitServiceUrl: string; status: number; + response: string; } const AuthConnectionRejected: FC = ({ livekitServiceUrl, status, + response, }) => { const { t } = useTranslation(); const [showDetails, setShowDetails] = useState(false); @@ -132,6 +134,7 @@ const AuthConnectionRejected: FC = ({ i18nKey="error.auth_connection_rejected_details" url={livekitServiceUrl} status={status} + response={response} >

The application connected to the call authentication service at{" "} @@ -139,7 +142,8 @@ const AuthConnectionRejected: FC = ({ {{ url: livekitServiceUrl } as unknown as ReactElement} , but it responded with status code{" "} - {{ status } as unknown as ReactElement}. If you are the server + {{ status } as unknown as ReactElement} ( + {{ response } as unknown as ReactElement}). If you are the server admin, make sure{" "} = ({ }; export class AuthConnectionRejectedError extends RichError { - public constructor(livekitServiceUrl: string, status: number) { + public constructor( + livekitServiceUrl: string, + status: number, + response: string, + ) { super( `Failed to connect to ${livekitServiceUrl} (status ${status})`, , ); } diff --git a/src/livekit/openIDSFU.test.ts b/src/livekit/openIDSFU.test.ts index 0e947c2e..320b12c6 100644 --- a/src/livekit/openIDSFU.test.ts +++ b/src/livekit/openIDSFU.test.ts @@ -59,9 +59,22 @@ test("getSFUConfigWithOpenID throws if connection fails", async () => { }); }); -test("getSFUConfigWithOpenID throws if server returns error", async () => { +test("getSFUConfigWithOpenID throws if endpoint is not found", async () => { await withFetchSpy(async (fetch) => { fetch.mockResolvedValue({ ok: false, status: 404 } as Response); + await expect(async () => + getSFUConfigWithOpenID(mockClient, mockFocus), + ).rejects.toThrowError(expect.any(AuthConnectionFailedError)); + }); +}); + +test("getSFUConfigWithOpenID throws if endpoint returns error", async () => { + await withFetchSpy(async (fetch) => { + fetch.mockResolvedValue({ + ok: false, + status: 503, + text: async () => Promise.resolve("Internal server error"), + } as Response); await expect(async () => getSFUConfigWithOpenID(mockClient, mockFocus), ).rejects.toThrowError(expect.any(AuthConnectionRejectedError)); diff --git a/src/livekit/openIDSFU.ts b/src/livekit/openIDSFU.ts index 076d6164..da6e5777 100644 --- a/src/livekit/openIDSFU.ts +++ b/src/livekit/openIDSFU.ts @@ -104,7 +104,13 @@ async function getLiveKitJWT( throw new AuthConnectionFailedError(livekitServiceURL, e); } if (!res.ok) { - throw new AuthConnectionRejectedError(livekitServiceURL, res.status); + throw res.status === 404 + ? new AuthConnectionFailedError(livekitServiceURL) + : new AuthConnectionRejectedError( + livekitServiceURL, + res.status, + await res.text(), + ); } return await res.json(); }