From a245373e0031a39bb296092af64ee695967f5621 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 30 Mar 2023 10:39:10 +0800 Subject: [PATCH] fix: fix getui.service cannot get client problem --- .../services/getui.service.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/plugins/com.msgbyte.getui/services/getui.service.ts b/server/plugins/com.msgbyte.getui/services/getui.service.ts index 099e4c11..4c054e20 100644 --- a/server/plugins/com.msgbyte.getui/services/getui.service.ts +++ b/server/plugins/com.msgbyte.getui/services/getui.service.ts @@ -1,3 +1,4 @@ +import { RequestError } from 'got'; import { TcService, TcDbService, InboxStruct, call } from 'tailchat-server-sdk'; import { GetuiClient } from '../lib/GetuiClient'; import type { GetuiLogDocument, GetuiLogModel } from '../models/log'; @@ -9,8 +10,6 @@ interface GetuiService extends TcService, TcDbService {} class GetuiService extends TcService { - client: GetuiClient = null; - get serviceName() { return 'plugin:com.msgbyte.getui'; } @@ -40,7 +39,8 @@ class GetuiService extends TcService { return; } - this.initClient(); + const { appId, appKey, masterSecert } = this.getuiInfo; + const client = new GetuiClient(appId, appKey, masterSecert); this.registerLocalDb(require('../models/log').default); this.registerEventListener( @@ -62,7 +62,7 @@ class GetuiService extends TcService { }; try { - await this.client.singlePush(userId, title, content, payload); + await client.singlePush(userId, title, content, payload); await this.adapter.model.create({ userId, title, @@ -71,24 +71,24 @@ class GetuiService extends TcService { success: true, }); } catch (err) { + let errorMsg = String(err); + + if (err instanceof RequestError && err.response) { + errorMsg = String(err.response.body); + } await this.adapter.model.create({ userId, title, content, payload, success: false, - errorMsg: String(err), + errorMsg, }); } } } ); } - - initClient() { - const { appId, appKey, masterSecert } = this.getuiInfo; - this.client = new GetuiClient(appId, appKey, masterSecert); - } } export default GetuiService;