diff --git a/backend/package.json b/backend/package.json index a7aee34..28097dc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.29", + "version": "2.14.30", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index a369084..0bdc2e3 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -32,10 +32,18 @@ async function downloadSubscription(req, res) { }); if (sub.source !== 'local') { - // forward flow headers - const flowInfo = await getFlowHeaders(sub.url); - if (flowInfo) { - res.set('subscription-userinfo', flowInfo); + try { + // forward flow headers + const flowInfo = await getFlowHeaders(sub.url); + if (flowInfo) { + res.set('subscription-userinfo', flowInfo); + } + } catch (err) { + $.error( + `订阅 ${name} 获取流量信息时发生错误: ${JSON.stringify( + err, + )}`, + ); } } @@ -50,15 +58,15 @@ async function downloadSubscription(req, res) { $.notify( `🌍 Sub-Store 下载订阅失败`, `❌ 无法下载订阅:${name}!`, - `🤔 原因:${JSON.stringify(err)}`, + `🤔 原因:${err.message ?? err}`, ); - $.error(JSON.stringify(err)); + $.error(err.message ?? err); failed( res, new InternalServerError( 'INTERNAL_SERVER_ERROR', `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) { const sub = findByName(allSubs, subnames[0]); if (sub.source !== 'local') { - const flowInfo = await getFlowHeaders(sub.url); - if (flowInfo) { - res.set('subscription-userinfo', flowInfo); + try { + const flowInfo = await getFlowHeaders(sub.url); + 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( 'INTERNAL_SERVER_ERROR', `Failed to download collection: ${name}`, - `Reason: ${JSON.stringify(err)}`, + `Reason: ${err.message ?? err}`, ), ); } diff --git a/backend/src/restful/miscs.js b/backend/src/restful/miscs.js index b03e146..e4f6af1 100644 --- a/backend/src/restful/miscs.js +++ b/backend/src/restful/miscs.js @@ -136,7 +136,7 @@ async function gistBackup(req, res) { new InternalServerError( 'BACKUP_FAILED', `Failed to ${action} data to gist!`, - `Reason: ${JSON.stringify(err)}`, + `Reason: ${err.message ?? err}`, ), ); } diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index fc88bc1..54b5140 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -42,6 +42,9 @@ async function produceArtifact({ type, name, platform }) { sub.process || [], platform, ); + if (proxies.length === 0) { + throw new Error(`订阅 ${name} 中不含有效节点`); + } // check duplicate const exist = {}; for (const proxy of proxies) { @@ -67,6 +70,7 @@ async function produceArtifact({ type, name, platform }) { const collection = findByName(allCols, name); const subnames = collection.subscriptions; const results = {}; + const errors = {}; let processed = 0; await Promise.all( @@ -97,6 +101,7 @@ async function produceArtifact({ type, name, platform }) { ); } catch (err) { processed++; + errors[name] = err; $.error( `❌ 处理组合订阅中的子订阅: ${ 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 let proxies = Array.prototype.concat.apply( [], - subnames.map((name) => results[name]), + subnames.map((name) => results[name] || []), ); // apply own processors @@ -121,7 +134,7 @@ async function produceArtifact({ type, name, platform }) { platform, ); if (proxies.length === 0) { - throw new Error(`组合订阅中不含有效节点!`); + throw new Error(`组合订阅 ${name} 中不含有效节点`); } // check duplicate const exist = {};