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

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