mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 15:03:16 +00:00
nodejs: send error events to bot (#7691)
* nodejs: send error events to bot * version --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
1 parent
599076d7a2
commit
eda94a505d
3 files changed
+18
-8
No files matched your search
@@ -80,6 +80,11 @@ export type DbConfig =
|
||||
connectionString: string
|
||||
}
|
||||
|
||||
function chatErrorEvent(err: unknown): ChatEvent {
|
||||
if (err instanceof core.ChatAPIError && err.chatError) return {type: "chatError", chatError: err.chatError}
|
||||
throw err
|
||||
}
|
||||
|
||||
function dbConfigToMigrateArgs(db: DbConfig): [string, string] {
|
||||
switch (db.type) {
|
||||
case "sqlite":
|
||||
@@ -171,7 +176,7 @@ export class ChatApi {
|
||||
private async runEventsLoop(): Promise<void> {
|
||||
while (this.receiveEvents) {
|
||||
try {
|
||||
const event = await this.recvChatEvent()
|
||||
const event = await this.recvChatEvent().catch(chatErrorEvent)
|
||||
if (!event) continue
|
||||
const subs = this.subscribers[event.type]
|
||||
if (subs) {
|
||||
@@ -194,12 +199,7 @@ export class ChatApi {
|
||||
}
|
||||
}
|
||||
} catch(err) {
|
||||
const e = err as core.ChatAPIError
|
||||
if ("chatError" in e) {
|
||||
console.log("Chat error", e.chatError)
|
||||
} else {
|
||||
console.log("Invalid event", e)
|
||||
}
|
||||
console.log("Invalid event", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user