improve error handling
This commit is contained in:
@ -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);
|
||||
})
|
||||
})
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user