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,9 +61,10 @@ export class LaanaWsServerAdapter implements ILaanaNetworkAdapter {
this.core.context.logger.logError('未实现的动作名', actionName);
return;
}
try {
// eslint-disable-next-line
// @ts-ignore
const ret = actionHandler(data.data.actionPing.ping[actionName]);
const ret = await actionHandler(data.data.actionPing.ping[actionName]);
this.checkStateAndReply(LaanaDataWrapper.toBinary({
data: {
oneofKind: 'actionPong',
@ -74,10 +75,27 @@ export class LaanaWsServerAdapter implements ILaanaNetworkAdapter {
pong: {
oneofKind: actionName,
[actionName]: ret,
}
},
},
},
}), 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 {
this.core.context.logger.logWarn('未知的数据包类型', data.data.oneofKind);
}