koishi-plugin-share-links-analysis 0.13.2 → 0.13.3
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/index.js +29 -6
- package/lib/parsers/twitter.js +15 -5
- package/lib/parsers/xiaoheihe.js +2 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -530,9 +530,15 @@ function apply(ctx, config) {
|
|
|
530
530
|
}
|
|
531
531
|
}
|
|
532
532
|
catch (e) {
|
|
533
|
+
let mergeErrDetail = e.message || String(e);
|
|
534
|
+
if (e.cause) {
|
|
535
|
+
const causeCode = e.cause.code || '';
|
|
536
|
+
const causeMsg = e.cause.message || String(e.cause);
|
|
537
|
+
mergeErrDetail += ` [cause: ${causeCode ? causeCode + ': ' : ''}${causeMsg}]`;
|
|
538
|
+
}
|
|
533
539
|
// 其他合并请求抛错时触发回退
|
|
534
540
|
if (optimisticData) {
|
|
535
|
-
logger.warn(`合并任务失败,触发乐观缓存回退: ${cacheKey}`);
|
|
541
|
+
logger.warn(`合并任务失败,触发乐观缓存回退: ${cacheKey} | Error: ${mergeErrDetail}`);
|
|
536
542
|
result = optimisticData;
|
|
537
543
|
const cacheTimeStr = new Date(optimisticTime).toLocaleString('zh-CN', { hour12: false });
|
|
538
544
|
result.mainbody = (result.mainbody || '') + `\n\n[⚠️ 并发请求异常,回退 L2 乐观缓存 | 缓存时间: ${cacheTimeStr}]`;
|
|
@@ -573,15 +579,22 @@ function apply(ctx, config) {
|
|
|
573
579
|
return res;
|
|
574
580
|
}
|
|
575
581
|
catch (e) {
|
|
582
|
+
// 构建包含根因的详细错误信息
|
|
583
|
+
let errDetail = e.message || String(e);
|
|
584
|
+
if (e.cause) {
|
|
585
|
+
const causeCode = e.cause.code || '';
|
|
586
|
+
const causeMsg = e.cause.message || String(e.cause);
|
|
587
|
+
errDetail += ` [cause: ${causeCode ? causeCode + ': ' : ''}${causeMsg}]`;
|
|
588
|
+
}
|
|
576
589
|
// 抛出异常(网络错误/封禁)时触发乐观回退
|
|
577
590
|
if (optimisticData) {
|
|
578
|
-
logger.warn(`解析抛出异常,触发乐观缓存回退: ${cacheKey} | Error: ${
|
|
591
|
+
logger.warn(`解析抛出异常,触发乐观缓存回退: ${cacheKey} | Error: ${errDetail}`);
|
|
579
592
|
const cacheTimeStr = new Date(optimisticTime).toLocaleString('zh-CN', { hour12: false });
|
|
580
593
|
optimisticData.mainbody = (optimisticData.mainbody || '') + `\n\n[⚠️ 接口触发异常,回退 L2 乐观缓存 | 缓存时间: ${cacheTimeStr}]`;
|
|
581
594
|
optimisticData._isOptimisticFallback = true;
|
|
582
595
|
return optimisticData;
|
|
583
596
|
}
|
|
584
|
-
logger.warn(`解析任务出错: ${
|
|
597
|
+
logger.warn(`解析任务出错: ${errDetail}`);
|
|
585
598
|
throw e;
|
|
586
599
|
}
|
|
587
600
|
finally {
|
|
@@ -619,9 +632,19 @@ function apply(ctx, config) {
|
|
|
619
632
|
}
|
|
620
633
|
catch (e) {
|
|
621
634
|
status = "error";
|
|
622
|
-
|
|
635
|
+
// 构建包含根因的详细错误信息
|
|
636
|
+
let details = e.message || String(e);
|
|
637
|
+
if (e.cause) {
|
|
638
|
+
const causeCode = e.cause.code || '';
|
|
639
|
+
const causeMsg = e.cause.message || String(e.cause);
|
|
640
|
+
details += ` [cause: ${causeCode ? causeCode + ': ' : ''}${causeMsg}]`;
|
|
641
|
+
}
|
|
642
|
+
if (e.response?.status) {
|
|
643
|
+
details += ` [HTTP ${e.response.status}]`;
|
|
644
|
+
}
|
|
645
|
+
errorMsg = details;
|
|
623
646
|
errorStack = e.stack || String(e);
|
|
624
|
-
logger.warn(`处理异常: ${
|
|
647
|
+
logger.warn(`处理异常: ${details}`);
|
|
625
648
|
}
|
|
626
649
|
finally {
|
|
627
650
|
// 4. 上报针对性排障数据
|
|
@@ -665,7 +688,7 @@ function apply(ctx, config) {
|
|
|
665
688
|
...resultFeatures,
|
|
666
689
|
// === 6. 错误追踪 ===
|
|
667
690
|
error_msg: errorMsg,
|
|
668
|
-
error_stack:
|
|
691
|
+
error_stack: truncatedStack,
|
|
669
692
|
// === 7. 耗时拆解 (性能瓶颈定位) ===
|
|
670
693
|
time_total_ms: totalTime,
|
|
671
694
|
time_parse_ms: parseTime, // 解析器发请求拉取数据的耗时
|
package/lib/parsers/twitter.js
CHANGED
|
@@ -238,7 +238,9 @@ async function handleSyndicationFallback(ctx, config, tweetId, session) {
|
|
|
238
238
|
const reqOptions = {
|
|
239
239
|
headers: {
|
|
240
240
|
'User-Agent': config.userAgent,
|
|
241
|
-
'Accept': '*/*'
|
|
241
|
+
'Accept': '*/*',
|
|
242
|
+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
|
243
|
+
'Referer': 'https://platform.twitter.com/'
|
|
242
244
|
}
|
|
243
245
|
};
|
|
244
246
|
if (config.proxy)
|
|
@@ -298,7 +300,10 @@ async function handleSyndicationFallback(ctx, config, tweetId, session) {
|
|
|
298
300
|
};
|
|
299
301
|
}
|
|
300
302
|
catch (e) {
|
|
301
|
-
|
|
303
|
+
const causeDetail = e.cause ? ` (cause: ${e.cause.code || e.cause.message || e.cause})` : '';
|
|
304
|
+
logger.error(`Syndication fallback failed: ${e.message}${causeDetail}`);
|
|
305
|
+
if (e.response?.status)
|
|
306
|
+
logger.error(` HTTP status: ${e.response.status}`);
|
|
302
307
|
// 抛出错误让外部统一处理 404 等信息
|
|
303
308
|
throw e;
|
|
304
309
|
}
|
|
@@ -372,16 +377,21 @@ async function process(ctx, config, link, session) {
|
|
|
372
377
|
// 404 通常意味着推文真的没了
|
|
373
378
|
const isNotFound = error.response?.status === 404;
|
|
374
379
|
if (!isNotFound) {
|
|
375
|
-
|
|
380
|
+
const causeDetail = error.cause ? ` (cause: ${error.cause.code || error.cause.message || error.cause})` : '';
|
|
381
|
+
logger.warn(`VxTwitter API 失败 (${error.message}${causeDetail}),尝试 Syndication API Fallback...`);
|
|
376
382
|
try {
|
|
377
383
|
return await handleSyndicationFallback(ctx, config, tweetId, session);
|
|
378
384
|
}
|
|
379
385
|
catch (fallbackError) {
|
|
380
|
-
|
|
386
|
+
const fbCauseDetail = fallbackError.cause ? ` (cause: ${fallbackError.cause.code || fallbackError.cause.message || fallbackError.cause})` : '';
|
|
387
|
+
logger.error(`Fallback 失败: ${fallbackError.message}${fbCauseDetail}`);
|
|
388
|
+
logger.error(`Twitter 解析失败: 主 API 和 Fallback 均失败`);
|
|
381
389
|
}
|
|
382
390
|
}
|
|
391
|
+
else {
|
|
392
|
+
logger.error(`Twitter 解析失败: ${error.message}`);
|
|
393
|
+
}
|
|
383
394
|
// 最终错误处理
|
|
384
|
-
logger.error(`Twitter 解析失败: ${error.message}`);
|
|
385
395
|
if (error.response?.status === 404) {
|
|
386
396
|
await session.send('推文不存在或已被删除');
|
|
387
397
|
}
|
package/lib/parsers/xiaoheihe.js
CHANGED
|
@@ -9,11 +9,11 @@ const utils_1 = require("../utils");
|
|
|
9
9
|
exports.name = "xiaoheihe";
|
|
10
10
|
const linkRules = [
|
|
11
11
|
{
|
|
12
|
-
pattern: /https?:\/\/api\.xiaoheihe\.cn\/v3\/bbs\/app\/api\/web\/share\?[^"'\s]*?\blink_id=(
|
|
12
|
+
pattern: /https?:\/\/api\.xiaoheihe\.cn\/v3\/bbs\/app\/api\/web\/share\?[^"'\s]*?\blink_id=([a-zA-Z0-9]+)/gi,
|
|
13
13
|
type: "bbs_api",
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
pattern: /https?:\/\/www\.xiaoheihe\.cn\/app\/bbs\/link\/(
|
|
16
|
+
pattern: /https?:\/\/www\.xiaoheihe\.cn\/app\/bbs\/link\/([a-zA-Z0-9]+)/gi,
|
|
17
17
|
type: "bbs",
|
|
18
18
|
}
|
|
19
19
|
];
|