retry for logEvent
This commit is contained in:
parent
7959e86f62
commit
3cbdf30bcd
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user