improve error handling

This commit is contained in:
2018-09-28 16:20:52 +08:00
parent 3f49544b1c
commit 242474085a
2 changed files with 5 additions and 3 deletions

View File

@ -153,7 +153,8 @@ function sendMessage(tab, req, cond, interval) {
console.log("request for", req.from);
let tabAvailable = await getTabByID(tab.id);
if (!tabAvailable) {
throw new Error("Task interupted due to the target tab is closed.");
reject("Task interupted due to the target tab is closed.");
return;
}
chrome.tabs.sendMessage(tab.id, req, r => {
@ -183,6 +184,7 @@ async function getActiveTab(currentWindow) {
async function getTabByID(id) {
return new Promise((resolve, reject) => {
chrome.tabs.get(id, function (tab) {
chrome.runtime.lastError;
resolve(tab);
})
})

View File

@ -47,7 +47,7 @@ class Extractor {
this._results[this._tasks[this._tasks.length - 1]] = result;
this.save();
}
);
).catch(err => console.log(err));
}
/**
* restart from specified task, but don't restart the previous tasks.
@ -76,7 +76,7 @@ class Extractor {
this._results[this._tasks[this._tasks.length - 1]] = result;
this.save();
}
);
).catch(err => console.log(err));
}
/**
* Save result of a task