fix: await & error handling

This commit is contained in:
Wesley F. Young 2024-09-07 01:16:40 +08:00
parent 90eb3da7f8
commit b802aad726

View File

@ -61,23 +61,41 @@ export class LaanaWsServerAdapter implements ILaanaNetworkAdapter {
this.core.context.logger.logError('未实现的动作名', actionName); this.core.context.logger.logError('未实现的动作名', actionName);
return; return;
} }
// eslint-disable-next-line try {
// @ts-ignore // eslint-disable-next-line
const ret = actionHandler(data.data.actionPing.ping[actionName]); // @ts-ignore
this.checkStateAndReply(LaanaDataWrapper.toBinary({ const ret = await actionHandler(data.data.actionPing.ping[actionName]);
data: { this.checkStateAndReply(LaanaDataWrapper.toBinary({
oneofKind: 'actionPong', data: {
actionPong: { oneofKind: 'actionPong',
clientPingId: data.data.actionPing.clientPingId, actionPong: {
// eslint-disable-next-line clientPingId: data.data.actionPing.clientPingId,
// @ts-ignore // eslint-disable-next-line
pong: { // @ts-ignore
oneofKind: actionName, pong: {
[actionName]: ret, oneofKind: actionName,
} [actionName]: ret,
},
},
}, },
}, }), wsClient);
}), wsClient); } catch (e: any) {
this.core.context.logger.logError('处理动作时出现错误', e);
this.checkStateAndReply(LaanaDataWrapper.toBinary({
data: {
oneofKind: 'actionPong',
actionPong: {
clientPingId: data.data.actionPing.clientPingId,
pong: {
oneofKind: 'failed',
failed: {
reason: e.toString(),
}
},
},
},
}), wsClient);
}
} else { } else {
this.core.context.logger.logWarn('未知的数据包类型', data.data.oneofKind); this.core.context.logger.logWarn('未知的数据包类型', data.data.oneofKind);
} }