From a40788a0f9a781831dffead8cae4c27223e31d42 Mon Sep 17 00:00:00 2001 From: ChengLei Shao Date: Mon, 6 Jan 2025 13:46:48 +0800 Subject: [PATCH] fix:ws message error (#5993) * chore: test * chore: hasLoadError status * chore: test --- .../client/src/application/Application.tsx | 9 +++- packages/core/server/src/gateway/ws-server.ts | 42 +++++++++---------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/packages/core/client/src/application/Application.tsx b/packages/core/client/src/application/Application.tsx index da928e9c77..f66810ace7 100644 --- a/packages/core/client/src/application/Application.tsx +++ b/packages/core/client/src/application/Application.tsx @@ -104,6 +104,7 @@ export class Application { maintained = false; maintaining = false; error = null; + hasLoadError = false; private wsAuthorized = false; @@ -302,6 +303,7 @@ export class Application { await this.loadWebSocket(); await this.pm.load(); } catch (error) { + this.hasLoadError = true; if (this.ws.enabled) { await new Promise((resolve) => { setTimeout(() => resolve(null), 1000); @@ -342,16 +344,21 @@ export class Application { window.location.reload(); return; } + if (data.type === 'notification') { this.notification[data.payload?.type || 'info']({ message: data.payload?.message }); return; } - const maintaining = data.type === 'maintaining' && data.payload.code !== 'APP_RUNNING'; + const maintaining = data.type === 'maintaining' && data.payload.code !== 'APP_RUNNING'; if (maintaining) { this.setMaintaining(true); this.error = data.payload; } else { + if (this.hasLoadError) { + window.location.reload(); + } + this.setMaintaining(false); this.maintained = true; this.error = null; diff --git a/packages/core/server/src/gateway/ws-server.ts b/packages/core/server/src/gateway/ws-server.ts index 4505cf10df..c435a25d16 100644 --- a/packages/core/server/src/gateway/ws-server.ts +++ b/packages/core/server/src/gateway/ws-server.ts @@ -187,31 +187,31 @@ export class WSServer extends EventEmitter { AppSupervisor.getInstance().bootStrapApp(handleAppName); } - const appStatus = AppSupervisor.getInstance().getAppStatus(handleAppName, 'initializing'); + // const appStatus = AppSupervisor.getInstance().getAppStatus(handleAppName, 'initializing'); - if (appStatus === 'not_found') { - this.sendMessageToConnection(client, { - type: 'maintaining', - payload: getPayloadByErrorCode('APP_NOT_FOUND', { appName: handleAppName }), - }); - return; - } + // if (appStatus === 'not_found') { + // this.sendMessageToConnection(client, { + // type: 'maintaining', + // payload: getPayloadByErrorCode('APP_NOT_FOUND', { appName: handleAppName }), + // }); + // return; + // } - if (appStatus === 'initializing') { - this.sendMessageToConnection(client, { - type: 'maintaining', - payload: getPayloadByErrorCode('APP_INITIALIZING', { appName: handleAppName }), - }); + // if (appStatus === 'initializing') { + // this.sendMessageToConnection(client, { + // type: 'maintaining', + // payload: getPayloadByErrorCode('APP_INITIALIZING', { appName: handleAppName }), + // }); - return; - } + // return; + // } - const app = await AppSupervisor.getInstance().getApp(handleAppName); - - this.sendMessageToConnection(client, { - type: 'maintaining', - payload: getPayloadByErrorCode(appStatus, { app }), - }); + // const app = await AppSupervisor.getInstance().getApp(handleAppName); + // + // this.sendMessageToConnection(client, { + // type: 'maintaining', + // payload: getPayloadByErrorCode(appStatus, { app }), + // }); } removeConnection(id: string) {