Fixed a bug when script download failed

This commit is contained in:
Peng-YM 2020-12-15 16:26:11 +08:00
parent a0d799c832
commit ff9586f2bd
2 changed files with 20 additions and 11 deletions

View File

@ -703,6 +703,11 @@ function service() {
let content; let content;
switch (action) { switch (action) {
case "upload": case "upload":
// update syncTime.
const settings = $.read(SETTINGS_KEY);
settings.syncTime = new Date().getTime();
$.write(settings, SETTINGS_KEY);
content = $.read("#sub-store"); content = $.read("#sub-store");
$.info(`上传备份中...`); $.info(`上传备份中...`);
await gist.upload({filename: GIST_BACKUP_FILE_NAME, content}); await gist.upload({filename: GIST_BACKUP_FILE_NAME, content});
@ -2642,14 +2647,18 @@ var ProxyUtils = (function () {
const {mode, content} = item.args; const {mode, content} = item.args;
if (mode === "link") { if (mode === "link") {
// if this is remote script, download it // if this is remote script, download it
script = await $.http try {
.get(content) script = await $.http
.then((resp) => resp.body) .get(content)
.catch((err) => { .then((resp) => resp.body);
throw new Error( } catch (err) {
`Error when downloading remote script: ${item.args.content}.\n Reason: ${err}` $.error(
); `Error when downloading remote script: ${item.args.content}.\n Reason: ${err}`
}); );
// skip the script if download failed.
continue;
}
} else { } else {
script = content; script = content;
} }
@ -2959,7 +2968,7 @@ var RuleUtils = (function () {
let matched; let matched;
try { try {
matched = parser.test(raw); matched = parser.test(raw);
} catch { } catch(err) {
matched = false; matched = false;
} }
if (matched) { if (matched) {

File diff suppressed because one or more lines are too long