Surface websocket constructor failures in renderer connect errors
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
7298c6cba6
commit
a5aae62386
2 files changed
+18
-4
No files matched your search
@@ -1974,7 +1974,9 @@ describe("wsNativeApi", () => {
|
||||
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
|
||||
const api = getOrCreateWsNativeApi();
|
||||
|
||||
await expect(api.todos.list()).rejects.toThrow("Failed to connect to local t3 runtime.");
|
||||
await expect(api.todos.list()).rejects.toThrow(
|
||||
"Failed to connect to local t3 runtime: websocket error (mock constructor failure).",
|
||||
);
|
||||
});
|
||||
|
||||
it("recovers after websocket construction failure on next request", async () => {
|
||||
@@ -1983,7 +1985,9 @@ describe("wsNativeApi", () => {
|
||||
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
|
||||
const api = getOrCreateWsNativeApi();
|
||||
|
||||
await expect(api.todos.list()).rejects.toThrow("Failed to connect to local t3 runtime.");
|
||||
await expect(api.todos.list()).rejects.toThrow(
|
||||
"Failed to connect to local t3 runtime: websocket error (mock constructor failure).",
|
||||
);
|
||||
|
||||
MockWebSocket.failConstruct = false;
|
||||
const secondRequest = api.todos.list();
|
||||
|
||||
@@ -99,6 +99,16 @@ function runtimeConnectErrorFromSocketError(event: unknown) {
|
||||
return new Error("Failed to connect to local t3 runtime.");
|
||||
}
|
||||
|
||||
function runtimeConnectErrorFromConstructionError(error: unknown) {
|
||||
const message = normalizeSocketErrorMessage(
|
||||
error instanceof Error ? error.message : (error as { message?: unknown } | null)?.message,
|
||||
);
|
||||
if (message) {
|
||||
return new Error(`Failed to connect to local t3 runtime: websocket error (${message}).`);
|
||||
}
|
||||
return new Error("Failed to connect to local t3 runtime.");
|
||||
}
|
||||
|
||||
function socketErrorMessage(event: unknown) {
|
||||
const directMessage = (event as { message?: unknown } | null)?.message;
|
||||
const normalizedDirectMessage = normalizeSocketErrorMessage(directMessage);
|
||||
@@ -161,8 +171,8 @@ class WsNativeApiClient {
|
||||
let socket: WebSocket;
|
||||
try {
|
||||
socket = new WebSocket(this.wsUrl);
|
||||
} catch {
|
||||
reject(new Error("Failed to connect to local t3 runtime."));
|
||||
} catch (error) {
|
||||
reject(runtimeConnectErrorFromConstructionError(error));
|
||||
return;
|
||||
}
|
||||
socket.binaryType = "arraybuffer";
|
||||
|
||||
Reference in new issue
Block a user