Count 404 as a connection failure

This commit is contained in:
Robin
2025-01-19 21:11:58 -05:00
parent 9b532e6720
commit 9dd540d91e
4 changed files with 34 additions and 6 deletions

View File

@@ -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}}</2>. If you are the server admin, check the network logs and make sure <5>lk-jwt-service</5> is listening at that address.</0>",
"auth_connection_rejected_details": "<0>The application connected to the call authentication service at <2>{{url}}</2>, but it responded with status code {{status}}. If you are the server admin, make sure <8>lk-jwt-service</8> is listening at that address and check the logs for more information.</0>",
"auth_connection_rejected_details": "<0>The application connected to the call authentication service at <2>{{url}}</2>, but it responded with status code {{status}} ({{response}}). If you are the server admin, make sure <10>lk-jwt-service</10> is listening at that address and check the logs for more information.</0>",
"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</1>.</0>",
"connection_failed": "Connection failed",

View File

@@ -102,7 +102,7 @@ const AuthConnectionFailed: FC<AuthConnectionFailedProps> = ({
};
export class AuthConnectionFailedError extends RichError {
public constructor(livekitServiceUrl: string, cause: unknown) {
public constructor(livekitServiceUrl: string, cause?: unknown) {
super(
`Failed to connect to ${livekitServiceUrl}`,
<AuthConnectionFailed livekitServiceUrl={livekitServiceUrl} />,
@@ -114,11 +114,13 @@ export class AuthConnectionFailedError extends RichError {
interface AuthConnectionRejectedProps {
livekitServiceUrl: string;
status: number;
response: string;
}
const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
livekitServiceUrl,
status,
response,
}) => {
const { t } = useTranslation();
const [showDetails, setShowDetails] = useState(false);
@@ -132,6 +134,7 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
i18nKey="error.auth_connection_rejected_details"
url={livekitServiceUrl}
status={status}
response={response}
>
<p>
The application connected to the call authentication service at{" "}
@@ -139,7 +142,8 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
{{ url: livekitServiceUrl } as unknown as ReactElement}
</Link>
, 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{" "}
<Link
href="https://github.com/element-hq/lk-jwt-service/"
@@ -161,12 +165,17 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
};
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})`,
<AuthConnectionRejected
livekitServiceUrl={livekitServiceUrl}
status={status}
response={response}
/>,
);
}

View File

@@ -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));

View File

@@ -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();
}