feat: 组合订阅错误信息将包含出现错误的子订阅名称; 获取流量失败时, 不影响节点订阅; 订阅上游无有效节点时将报错

This commit is contained in:
xream 2023-08-26 20:27:12 +08:00
parent 8c5dca71fb
commit 5e14d05c30
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
4 changed files with 44 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.29", "version": "2.14.30",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -32,10 +32,18 @@ async function downloadSubscription(req, res) {
}); });
if (sub.source !== 'local') { if (sub.source !== 'local') {
// forward flow headers try {
const flowInfo = await getFlowHeaders(sub.url); // forward flow headers
if (flowInfo) { const flowInfo = await getFlowHeaders(sub.url);
res.set('subscription-userinfo', flowInfo); if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
} catch (err) {
$.error(
`订阅 ${name} 获取流量信息时发生错误: ${JSON.stringify(
err,
)}`,
);
} }
} }
@ -50,15 +58,15 @@ async function downloadSubscription(req, res) {
$.notify( $.notify(
`🌍 Sub-Store 下载订阅失败`, `🌍 Sub-Store 下载订阅失败`,
`❌ 无法下载订阅:${name}`, `❌ 无法下载订阅:${name}`,
`🤔 原因:${JSON.stringify(err)}`, `🤔 原因:${err.message ?? err}`,
); );
$.error(JSON.stringify(err)); $.error(err.message ?? err);
failed( failed(
res, res,
new InternalServerError( new InternalServerError(
'INTERNAL_SERVER_ERROR', 'INTERNAL_SERVER_ERROR',
`Failed to download subscription: ${name}`, `Failed to download subscription: ${name}`,
`Reason: ${JSON.stringify(err)}`, `Reason: ${err.message ?? err}`,
), ),
); );
} }
@ -101,9 +109,17 @@ async function downloadCollection(req, res) {
if (subnames.length > 0) { if (subnames.length > 0) {
const sub = findByName(allSubs, subnames[0]); const sub = findByName(allSubs, subnames[0]);
if (sub.source !== 'local') { if (sub.source !== 'local') {
const flowInfo = await getFlowHeaders(sub.url); try {
if (flowInfo) { const flowInfo = await getFlowHeaders(sub.url);
res.set('subscription-userinfo', flowInfo); if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
} catch (err) {
$.error(
`组合订阅 ${name} 中的子订阅 ${
sub.name
} 获取流量信息时发生错误: ${err.message ?? err}`,
);
} }
} }
} }
@ -126,7 +142,7 @@ async function downloadCollection(req, res) {
new InternalServerError( new InternalServerError(
'INTERNAL_SERVER_ERROR', 'INTERNAL_SERVER_ERROR',
`Failed to download collection: ${name}`, `Failed to download collection: ${name}`,
`Reason: ${JSON.stringify(err)}`, `Reason: ${err.message ?? err}`,
), ),
); );
} }

View File

@ -136,7 +136,7 @@ async function gistBackup(req, res) {
new InternalServerError( new InternalServerError(
'BACKUP_FAILED', 'BACKUP_FAILED',
`Failed to ${action} data to gist!`, `Failed to ${action} data to gist!`,
`Reason: ${JSON.stringify(err)}`, `Reason: ${err.message ?? err}`,
), ),
); );
} }

View File

@ -42,6 +42,9 @@ async function produceArtifact({ type, name, platform }) {
sub.process || [], sub.process || [],
platform, platform,
); );
if (proxies.length === 0) {
throw new Error(`订阅 ${name} 中不含有效节点`);
}
// check duplicate // check duplicate
const exist = {}; const exist = {};
for (const proxy of proxies) { for (const proxy of proxies) {
@ -67,6 +70,7 @@ async function produceArtifact({ type, name, platform }) {
const collection = findByName(allCols, name); const collection = findByName(allCols, name);
const subnames = collection.subscriptions; const subnames = collection.subscriptions;
const results = {}; const results = {};
const errors = {};
let processed = 0; let processed = 0;
await Promise.all( await Promise.all(
@ -97,6 +101,7 @@ async function produceArtifact({ type, name, platform }) {
); );
} catch (err) { } catch (err) {
processed++; processed++;
errors[name] = err;
$.error( $.error(
`❌ 处理组合订阅中的子订阅: ${ `❌ 处理组合订阅中的子订阅: ${
sub.name sub.name
@ -108,10 +113,18 @@ async function produceArtifact({ type, name, platform }) {
}), }),
); );
if (Object.keys(errors).length > 0) {
throw new Error(
`组合订阅 ${name} 中的子订阅 ${Object.keys(errors).join(
', ',
)} 发生错误, 请查看日志`,
);
}
// merge proxies with the original order // merge proxies with the original order
let proxies = Array.prototype.concat.apply( let proxies = Array.prototype.concat.apply(
[], [],
subnames.map((name) => results[name]), subnames.map((name) => results[name] || []),
); );
// apply own processors // apply own processors
@ -121,7 +134,7 @@ async function produceArtifact({ type, name, platform }) {
platform, platform,
); );
if (proxies.length === 0) { if (proxies.length === 0) {
throw new Error(`组合订阅中不含有效节点`); throw new Error(`组合订阅 ${name} 中不含有效节点`);
} }
// check duplicate // check duplicate
const exist = {}; const exist = {};