koishi-plugin-cs2-update-log 2.1.1 → 2.1.2
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 +79 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -103,7 +103,12 @@ function apply(ctx, config) {
|
|
|
103
103
|
async function fetchNews() {
|
|
104
104
|
try {
|
|
105
105
|
const xml = await ctx.http.get(STEAM_RSS_URL, {
|
|
106
|
+
headers: {
|
|
107
|
+
Accept: 'application/rss+xml, application/xml, text/xml;q=0.9, */*;q=0.8',
|
|
108
|
+
'User-Agent': 'koishi-plugin-cs2-update-log/2.1',
|
|
109
|
+
},
|
|
106
110
|
responseType: 'text',
|
|
111
|
+
timeout: 30000,
|
|
107
112
|
});
|
|
108
113
|
const parsed = rssParser.parse(xml);
|
|
109
114
|
const rawItems = parsed.rss?.channel?.item;
|
|
@@ -114,7 +119,7 @@ function apply(ctx, config) {
|
|
|
114
119
|
.slice(0, config.count);
|
|
115
120
|
}
|
|
116
121
|
catch (error) {
|
|
117
|
-
logger.error('拉取 Steam CS2 RSS
|
|
122
|
+
logger.error('拉取 Steam CS2 RSS 失败:url=%s\n%s', STEAM_RSS_URL, formatError(error));
|
|
118
123
|
return [];
|
|
119
124
|
}
|
|
120
125
|
}
|
|
@@ -791,7 +796,77 @@ function isNodeError(error) {
|
|
|
791
796
|
return !!error && typeof error === 'object' && 'code' in error;
|
|
792
797
|
}
|
|
793
798
|
function formatError(error) {
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
return
|
|
799
|
+
const lines = [];
|
|
800
|
+
appendErrorDetails(lines, error);
|
|
801
|
+
return lines.join('\n');
|
|
802
|
+
}
|
|
803
|
+
function appendErrorDetails(lines, error, label = 'error', depth = 0, seen = new Set()) {
|
|
804
|
+
if (error == null || typeof error !== 'object') {
|
|
805
|
+
lines.push(`${label}: ${String(error)}`);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (seen.has(error)) {
|
|
809
|
+
lines.push(`${label}: [Circular]`);
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
seen.add(error);
|
|
813
|
+
const record = error;
|
|
814
|
+
const name = typeof record.name === 'string' ? record.name : error instanceof Error ? error.name : 'Error';
|
|
815
|
+
const message = typeof record.message === 'string' ? record.message : String(error);
|
|
816
|
+
lines.push(`${label}: ${name}: ${message}`);
|
|
817
|
+
const details = collectErrorDetails(record);
|
|
818
|
+
if (details.length)
|
|
819
|
+
lines.push(`${label} details: ${details.join(', ')}`);
|
|
820
|
+
const stack = typeof record.stack === 'string' ? record.stack : '';
|
|
821
|
+
const stackLines = stack.split(/\r?\n/).slice(1, 7).map((line) => line.trim()).filter(Boolean);
|
|
822
|
+
if (stackLines.length)
|
|
823
|
+
lines.push(`${label} stack:\n ${stackLines.join('\n ')}`);
|
|
824
|
+
appendNestedObjectDetails(lines, record, 'request', label);
|
|
825
|
+
appendNestedObjectDetails(lines, record, 'response', label);
|
|
826
|
+
const cause = record.cause;
|
|
827
|
+
if (cause !== undefined && depth < 5) {
|
|
828
|
+
appendErrorDetails(lines, cause, `${label}.cause`, depth + 1, seen);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function collectErrorDetails(record) {
|
|
832
|
+
const keys = [
|
|
833
|
+
'code',
|
|
834
|
+
'errno',
|
|
835
|
+
'type',
|
|
836
|
+
'syscall',
|
|
837
|
+
'hostname',
|
|
838
|
+
'host',
|
|
839
|
+
'address',
|
|
840
|
+
'port',
|
|
841
|
+
'method',
|
|
842
|
+
'url',
|
|
843
|
+
'status',
|
|
844
|
+
'statusCode',
|
|
845
|
+
'statusText',
|
|
846
|
+
];
|
|
847
|
+
const details = [];
|
|
848
|
+
for (const key of keys) {
|
|
849
|
+
const value = record[key];
|
|
850
|
+
if (value == null)
|
|
851
|
+
continue;
|
|
852
|
+
const rendered = renderLogValue(value);
|
|
853
|
+
if (rendered)
|
|
854
|
+
details.push(`${key}=${rendered}`);
|
|
855
|
+
}
|
|
856
|
+
return details;
|
|
857
|
+
}
|
|
858
|
+
function appendNestedObjectDetails(lines, record, key, label) {
|
|
859
|
+
const value = record[key];
|
|
860
|
+
if (!value || typeof value !== 'object')
|
|
861
|
+
return;
|
|
862
|
+
const details = collectErrorDetails(value);
|
|
863
|
+
if (details.length)
|
|
864
|
+
lines.push(`${label}.${key} details: ${details.join(', ')}`);
|
|
865
|
+
}
|
|
866
|
+
function renderLogValue(value) {
|
|
867
|
+
if (typeof value === 'string')
|
|
868
|
+
return value;
|
|
869
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint')
|
|
870
|
+
return String(value);
|
|
871
|
+
return undefined;
|
|
797
872
|
}
|
package/package.json
CHANGED