From 4ac9940a424851d8ab19850671d902bb3d7489d1 Mon Sep 17 00:00:00 2001 From: Luo Tim Date: Tue, 11 Jun 2024 18:39:19 +0800 Subject: [PATCH] Handle address not fetched on initialization --- src/util/APIUtil.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/APIUtil.ts b/src/util/APIUtil.ts index a0efc3e..df1b1ba 100644 --- a/src/util/APIUtil.ts +++ b/src/util/APIUtil.ts @@ -44,8 +44,7 @@ class APIUtil { console.log('Webapp url: ', href) return href; } catch (err) { - console.error("Error fetch webapp url:", err); - return "https://app.devchat.ai"; + throw(`Error fetch webapp url: ${err}`) } } @@ -55,6 +54,8 @@ class APIUtil { if (!this.webappUrl) { this.fetchWebappUrl().then(url => { this.webappUrl = url; + }).catch(err => { + console.error(err); }) } } @@ -62,6 +63,7 @@ class APIUtil { async createMessage(message: object) { this.currentMessageId = `msg-${uuidv4()}`; try { + if (!this.webappUrl) this.webappUrl = await this.fetchWebappUrl(); const res = await axios.post( `${this.webappUrl}/api/v1/messages`, {...message, message_id: this.currentMessageId}, @@ -78,6 +80,7 @@ class APIUtil { async createEvent(event: object) { try { + if (!this.webappUrl) this.webappUrl = await this.fetchWebappUrl(); const res = await axios.post( `${this.webappUrl}/api/v1/messages/${this.currentMessageId}/events`, event,