mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-18 18:59:23 +00:00
Count 404 as a connection failure
This commit is contained in:
@@ -73,7 +73,7 @@
|
|||||||
"disconnected_banner": "Connectivity to the server has been lost.",
|
"disconnected_banner": "Connectivity to the server has been lost.",
|
||||||
"error": {
|
"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_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": "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>",
|
"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",
|
"connection_failed": "Connection failed",
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ const AuthConnectionFailed: FC<AuthConnectionFailedProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class AuthConnectionFailedError extends RichError {
|
export class AuthConnectionFailedError extends RichError {
|
||||||
public constructor(livekitServiceUrl: string, cause: unknown) {
|
public constructor(livekitServiceUrl: string, cause?: unknown) {
|
||||||
super(
|
super(
|
||||||
`Failed to connect to ${livekitServiceUrl}`,
|
`Failed to connect to ${livekitServiceUrl}`,
|
||||||
<AuthConnectionFailed livekitServiceUrl={livekitServiceUrl} />,
|
<AuthConnectionFailed livekitServiceUrl={livekitServiceUrl} />,
|
||||||
@@ -114,11 +114,13 @@ export class AuthConnectionFailedError extends RichError {
|
|||||||
interface AuthConnectionRejectedProps {
|
interface AuthConnectionRejectedProps {
|
||||||
livekitServiceUrl: string;
|
livekitServiceUrl: string;
|
||||||
status: number;
|
status: number;
|
||||||
|
response: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
|
const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
|
||||||
livekitServiceUrl,
|
livekitServiceUrl,
|
||||||
status,
|
status,
|
||||||
|
response,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [showDetails, setShowDetails] = useState(false);
|
const [showDetails, setShowDetails] = useState(false);
|
||||||
@@ -132,6 +134,7 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
|
|||||||
i18nKey="error.auth_connection_rejected_details"
|
i18nKey="error.auth_connection_rejected_details"
|
||||||
url={livekitServiceUrl}
|
url={livekitServiceUrl}
|
||||||
status={status}
|
status={status}
|
||||||
|
response={response}
|
||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
The application connected to the call authentication service at{" "}
|
The application connected to the call authentication service at{" "}
|
||||||
@@ -139,7 +142,8 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
|
|||||||
{{ url: livekitServiceUrl } as unknown as ReactElement}
|
{{ url: livekitServiceUrl } as unknown as ReactElement}
|
||||||
</Link>
|
</Link>
|
||||||
, but it responded with status code{" "}
|
, 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{" "}
|
admin, make sure{" "}
|
||||||
<Link
|
<Link
|
||||||
href="https://github.com/element-hq/lk-jwt-service/"
|
href="https://github.com/element-hq/lk-jwt-service/"
|
||||||
@@ -161,12 +165,17 @@ const AuthConnectionRejected: FC<AuthConnectionRejectedProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class AuthConnectionRejectedError extends RichError {
|
export class AuthConnectionRejectedError extends RichError {
|
||||||
public constructor(livekitServiceUrl: string, status: number) {
|
public constructor(
|
||||||
|
livekitServiceUrl: string,
|
||||||
|
status: number,
|
||||||
|
response: string,
|
||||||
|
) {
|
||||||
super(
|
super(
|
||||||
`Failed to connect to ${livekitServiceUrl} (status ${status})`,
|
`Failed to connect to ${livekitServiceUrl} (status ${status})`,
|
||||||
<AuthConnectionRejected
|
<AuthConnectionRejected
|
||||||
livekitServiceUrl={livekitServiceUrl}
|
livekitServiceUrl={livekitServiceUrl}
|
||||||
status={status}
|
status={status}
|
||||||
|
response={response}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) => {
|
await withFetchSpy(async (fetch) => {
|
||||||
fetch.mockResolvedValue({ ok: false, status: 404 } as Response);
|
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 () =>
|
await expect(async () =>
|
||||||
getSFUConfigWithOpenID(mockClient, mockFocus),
|
getSFUConfigWithOpenID(mockClient, mockFocus),
|
||||||
).rejects.toThrowError(expect.any(AuthConnectionRejectedError));
|
).rejects.toThrowError(expect.any(AuthConnectionRejectedError));
|
||||||
|
|||||||
@@ -104,7 +104,13 @@ async function getLiveKitJWT(
|
|||||||
throw new AuthConnectionFailedError(livekitServiceURL, e);
|
throw new AuthConnectionFailedError(livekitServiceURL, e);
|
||||||
}
|
}
|
||||||
if (!res.ok) {
|
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();
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user