diff --git a/src/util/APIUtil.ts b/src/util/APIUtil.ts index 764b57b..c100afa 100644 --- a/src/util/APIUtil.ts +++ b/src/util/APIUtil.ts @@ -78,9 +78,11 @@ class APIUtil { } } - async createEvent(event: object, messageId?: string) { - // 如果 messageId 为空,则使用当前的 messageId - const idToUse = messageId || this.currentMessageId; +async createEvent(event: object, messageId?: string) { + // 如果 messageId 为空,则使用当前的 messageId + const idToUse = messageId || this.currentMessageId; + + const attemptCreate = async () => { try { if (!this.webappUrl) this.webappUrl = await this.fetchWebappUrl(); const res = await axios.post( @@ -92,10 +94,22 @@ class APIUtil { }} ); console.log("Event created: ", res?.data); + return true; // 成功创建事件 } catch(err) { + if (axios.isAxiosError(err) && err.response?.status === 404) { + return false; // 遇到 404 错误,返回 false + } console.error(err); + return true; // 其他错误,不再重试 } + }; + + if (!(await attemptCreate())) { + // 如果第一次尝试失败且是 404 错误,等待 2 秒后重试 + await new Promise(resolve => setTimeout(resolve, 2000)); + await attemptCreate(); } +} async getBalance() { try {