From f118c6b6f51b6ede9458d5beeb5f41eab440a87c Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 21 Sep 2025 16:12:31 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E7=B9=95=E5=AE=A2=E6=88=B6?= =?UTF-8?q?=E7=AB=AF=E8=AB=8B=E6=B1=82=E5=85=81=E8=A8=B1=E7=AD=89=E5=BE=85?= =?UTF-8?q?=E9=80=A3=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/api/ApiCallbackMessage.ts | 5 +++-- client/api/Client.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client/api/ApiCallbackMessage.ts b/client/api/ApiCallbackMessage.ts index e94b2df..6f2bc8e 100644 --- a/client/api/ApiCallbackMessage.ts +++ b/client/api/ApiCallbackMessage.ts @@ -8,8 +8,9 @@ type ApiCallbackMessage = { * 404: Not Found * 500: 伺服器端錯誤 * 501: 伺服器端不支持請求的功能 + * -1: 客戶端錯誤 */ - code: 200 | 400 | 401 | 403 | 404 | 500 | 501, - data?: { [key: string]: unknown }, + code: 200 | 400 | 401 | 403 | 404 | 500 | 501 | -1 + data?: { [key: string]: unknown } } export default ApiCallbackMessage diff --git a/client/api/Client.ts b/client/api/Client.ts index a9ae69b..9aa72ea 100644 --- a/client/api/Client.ts +++ b/client/api/Client.ts @@ -9,7 +9,7 @@ type UnknownObject = { [key: string]: unknown } class Client { static myUserProfile?: User static socket?: Socket - static events: { [key: string]: (data: UnknownObject) => UnknownObject | undefined } = {} + static events: { [key: string]: (data: UnknownObject) => UnknownObject | void } = {} static connect() { if (data.device_id == null) data.device_id = crypto.randomUUID() @@ -37,9 +37,12 @@ class Client { setTimeout(async () => reslove(await this.invoke(method, args, timeout)), 500) }) } - return new Promise((resolve, reject) => { + return new Promise((resolve) => { this.socket!.timeout(timeout).emit("The_White_Silk", method, args, (err: string, res: ApiCallbackMessage) => { - if (err) return reject(err) + if (err) return resolve({ + code: -1, + msg: err, + }) resolve(res) }) }) @@ -57,7 +60,7 @@ class Client { token: data.access_token })).data as unknown as User } - static on(eventName: ClientEvent, func: (data: UnknownObject) => UnknownObject) { + static on(eventName: ClientEvent, func: (data: UnknownObject) => UnknownObject | void) { this.events[eventName] = func } static off(eventName: ClientEvent) {