fix: improve WebSocket close reason normalization in LighterGateway for better error handling

This commit is contained in:
discountry
2025-11-08 12:10:47 +08:00
parent a91e87534b
commit 274e2f3d75
+1 -1
View File
@@ -488,7 +488,7 @@ export class LighterGateway {
});
ws.on("close", (code, reason) => {
cleanup();
const normalizedReason = typeof reason === "string" && reason.length ? reason : undefined;
const normalizedReason = Buffer.isBuffer(reason) && reason.length > 0 ? reason.toString("utf8") : undefined;
if (!settled) {
fail(new Error(`WebSocket closed before ready (code=${code}${normalizedReason ? `, reason=${normalizedReason}` : ""})`));
return;