@seamnet/client 0.12.6 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/guardian.js +18 -0
- package/lib/plugins/im/index.cjs +23 -0
- package/package.json +1 -1
package/lib/guardian.js
CHANGED
|
@@ -240,6 +240,24 @@ export async function guardianRun() {
|
|
|
240
240
|
};
|
|
241
241
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
242
242
|
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
243
|
+
|
|
244
|
+
// 最后防线:未捕获异常/Promise 只记录不退出,防止 SDK 一个错误把整个 guardian 炸了
|
|
245
|
+
process.on('uncaughtException', (err) => {
|
|
246
|
+
try {
|
|
247
|
+
hub.logger('guardian').error('uncaught_exception', err, {
|
|
248
|
+
message: err?.message?.slice(0, 300),
|
|
249
|
+
code: err?.code,
|
|
250
|
+
});
|
|
251
|
+
} catch {}
|
|
252
|
+
});
|
|
253
|
+
process.on('unhandledRejection', (reason) => {
|
|
254
|
+
try {
|
|
255
|
+
hub.logger('guardian').error('unhandled_rejection', reason, {
|
|
256
|
+
message: reason?.message?.slice(0, 300) || String(reason).slice(0, 300),
|
|
257
|
+
code: reason?.code,
|
|
258
|
+
});
|
|
259
|
+
} catch {}
|
|
260
|
+
});
|
|
243
261
|
}
|
|
244
262
|
|
|
245
263
|
export async function guardianStop() {
|
package/lib/plugins/im/index.cjs
CHANGED
|
@@ -374,6 +374,29 @@ function createImPlugin() {
|
|
|
374
374
|
log.warn('sdk_not_ready');
|
|
375
375
|
});
|
|
376
376
|
|
|
377
|
+
// SDK 错误事件:记录但不 throw,避免 guardian 整个 crash
|
|
378
|
+
chat.on(TencentCloudChat.EVENT.ERROR, (event) => {
|
|
379
|
+
const err = event?.data || event;
|
|
380
|
+
log.warn('sdk_error', {
|
|
381
|
+
code: err?.code,
|
|
382
|
+
message: err?.message || String(err).slice(0, 200),
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// 被踢下线(2801 等多端登录场景):记录,SDK 会自动重连
|
|
387
|
+
chat.on(TencentCloudChat.EVENT.KICKED_OUT, (event) => {
|
|
388
|
+
log.warn('sdk_kicked_out', {
|
|
389
|
+
type: event?.data?.type,
|
|
390
|
+
message: event?.data?.message,
|
|
391
|
+
});
|
|
392
|
+
sdkReady = false;
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// 网络状态变化:断线/重连都只记日志,不干扰主流程
|
|
396
|
+
chat.on(TencentCloudChat.EVENT.NET_STATE_CHANGE, (event) => {
|
|
397
|
+
log.info('sdk_net_state', { state: event?.data?.state });
|
|
398
|
+
});
|
|
399
|
+
|
|
377
400
|
chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, (event) => {
|
|
378
401
|
for (const msg of event.data) {
|
|
379
402
|
if (msg.from === myUserId) continue;
|