mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-12-15 07:40:01 +08:00
Fix: Node Request i18n
This commit is contained in:
parent
8a8603b46e
commit
3e7307e2a3
@ -175,7 +175,7 @@ class InstanceSubsystem extends EventEmitter {
|
||||
const instance = this.getInstance(instanceUuid);
|
||||
if (instance) {
|
||||
if (instance.status() !== Instance.STATUS_STOP)
|
||||
throw new Error($t("请确保实例处于停止状态再删除!"));
|
||||
throw new Error($t("TXT_CODE_fb547313"));
|
||||
instance.destroy();
|
||||
this.instances.delete(instanceUuid);
|
||||
StorageSubsystem.delete("InstanceConfig", instanceUuid);
|
||||
@ -183,7 +183,7 @@ class InstanceSubsystem extends EventEmitter {
|
||||
if (deleteFile) fs.remove(instance.config.cwd, (err) => {});
|
||||
return true;
|
||||
}
|
||||
throw new Error($t("目标实例不存在!"));
|
||||
throw new Error($t("TXT_CODE_3bfb9e04"));
|
||||
}
|
||||
|
||||
forward(targetInstanceUuid: string, socket: Socket) {
|
||||
|
@ -1831,5 +1831,12 @@
|
||||
"TXT_CODE_d58ffa0f": "实例未处于运行中状态!",
|
||||
"TXT_CODE_d324bb21": "访问地址:",
|
||||
"TXT_CODE_cdf7c16a": "这些设置只有管理员能够查看与更改",
|
||||
"TXT_CODE_b51bac6f": "使用 Docker 镜像创建实例,您必须确保 Docker 已正确安装!"
|
||||
"TXT_CODE_b51bac6f": "使用 Docker 镜像创建实例,您必须确保 Docker 已正确安装!",
|
||||
"TXT_CODE_fb547313": "请确保实例处于停止状态再删除!",
|
||||
"TXT_CODE_3bfb9e04": "目标实例不存在!",
|
||||
"TXT_CODE_ca8072bd": "初始化失败,远程节点不存在!",
|
||||
"TXT_CODE_3d94ea16": "节点 Socket 异常,请尝试在节点管理中重新连接!",
|
||||
"TXT_CODE_b7d38e78": "远程节点不可用!请联系管理员前往节点列表检查远程节点状态!",
|
||||
"TXT_CODE_7c650d80": "节点连接失败,请联系管理员检查远程节点状态!",
|
||||
"TXT_CODE_bd99b64e": "请求超时!请联系管理员检查节点网络状态,节点IP:"
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { v4 } from "uuid";
|
||||
import { IPacket, IRequestPacket } from "../entity/entity_interface";
|
||||
import RemoteService from "../entity/remote_service";
|
||||
import { $t } from "../i18n";
|
||||
|
||||
class RemoteError extends Error {
|
||||
constructor(msg: string) {
|
||||
@ -12,33 +13,26 @@ class RemoteError extends Error {
|
||||
// and support synchronous response data (such as HTTP).
|
||||
export default class RemoteRequest {
|
||||
constructor(public readonly rService: RemoteService) {
|
||||
if (!this.rService || !this.rService.socket)
|
||||
throw new Error("Unable to complete initialization, remote service does not exist.");
|
||||
if (!this.rService || !this.rService.socket) throw new Error($t("TXT_CODE_ca8072bd"));
|
||||
}
|
||||
|
||||
// request to remote daemon
|
||||
public async request(event: string, data?: any, timeout = 6000, force = false): Promise<any> {
|
||||
if (!this.rService.socket)
|
||||
throw new Error("The Socket must be SocketIOClient.Socket, Not null.");
|
||||
if (!this.rService.socket) throw new Error($t("TXT_CODE_3d94ea16"));
|
||||
if (!this.rService.available && !force)
|
||||
throw new Error(
|
||||
"The remote daemon is not available. Try reconnecting to the remote daemon or check the configuration"
|
||||
);
|
||||
throw new Error($t("TXT_CODE_b7d38e78") + ` IP: ${this.rService.config.ip}`);
|
||||
if (!this.rService.socket.connected && !force)
|
||||
throw new Error("The remote daemon connection is unavailable");
|
||||
throw new Error($t("TXT_CODE_7c650d80") + ` IP: ${this.rService.config.ip}`);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const uuid = [v4(), new Date().getTime()].join("");
|
||||
const protocolData: IRequestPacket = { uuid, data };
|
||||
|
||||
// Start countdown
|
||||
let countdownTask: NodeJS.Timeout;
|
||||
if (timeout) {
|
||||
countdownTask = setTimeout(
|
||||
() =>
|
||||
reject(
|
||||
new RemoteError(`Request daemon:(${this.rService.config.ip}) [${event}] timeout`)
|
||||
),
|
||||
reject(new RemoteError([$t("TXT_CODE_bd99b64e"), this.rService.config.ip].join(" "))),
|
||||
timeout
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user