mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-19 16:51:35 +00:00
fix(whatsapp): preserve disconnect errors (#105399)
This commit is contained in:
committed by
GitHub
parent
baa9eb4d7b
commit
b16be75cf2
@@ -597,6 +597,24 @@ describe("web session", () => {
|
||||
await expect(promise).rejects.toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it("preserves the underlying Baileys disconnect error", async () => {
|
||||
const ev = new EventEmitter();
|
||||
const promise = waitForWaConnection(
|
||||
{ ev } as unknown as ReturnType<typeof baileys.makeWASocket>,
|
||||
{ timeout: "none" },
|
||||
);
|
||||
const disconnectError = Object.assign(new Error("logged out"), {
|
||||
output: { statusCode: 401 },
|
||||
});
|
||||
ev.emit("connection.update", {
|
||||
connection: "close",
|
||||
lastDisconnect: { date: new Date(), error: disconnectError },
|
||||
});
|
||||
const error = await promise.catch((caught: unknown) => caught);
|
||||
expect(error).toBe(disconnectError);
|
||||
expect(error).toMatchObject({ message: "logged out", output: { statusCode: 401 } });
|
||||
});
|
||||
|
||||
it("rejects after timeout with no connection event", async () => {
|
||||
vi.useFakeTimers();
|
||||
const ev = new EventEmitter();
|
||||
|
||||
@@ -513,9 +513,10 @@ export async function waitForWaConnection(
|
||||
}
|
||||
if (update.connection === "close") {
|
||||
cleanup();
|
||||
const disconnectError = update.lastDisconnect?.error ?? update.lastDisconnect;
|
||||
reject(
|
||||
toLintErrorObject(
|
||||
update.lastDisconnect ?? new Error("Connection closed"),
|
||||
disconnectError ?? new Error("Connection closed"),
|
||||
"Non-Error rejection",
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user