Added catch statements

This commit is contained in:
Kevin Röbert 2020-02-20 14:12:06 +01:00
parent a44e13645c
commit f7949e89f6
8 changed files with 41 additions and 45 deletions

View File

@ -1,6 +1,6 @@
{
"extension_description": {
"message": "Entfernt tracking Elemente von URLs.",
"message": "Entfernt Tracking-Elemente von URLs.",
"description": "Erweiterungsbeschreibung (max. 132 Zeichen)"
},
"hash_status_code_1": {

View File

@ -579,7 +579,7 @@ function start() {
if (result.redirect) {
if (providers[i].shouldForceRedirect() &&
request.type === 'main_frame') {
browser.tabs.update(request.tabId, {url: result.url});
browser.tabs.update(request.tabId, {url: result.url}).catch(handleError);
return {cancel: true};
}
@ -595,7 +595,7 @@ function start() {
if (result.cancel) {
if (request.type === 'main_frame') {
const blockingPage = browser.extension.getURL("html/siteBlockedAlert.html?source=" + encodeURIComponent(request.url));
browser.tabs.update(request.tabId, {url: blockingPage});
browser.tabs.update(request.tabId, {url: blockingPage}).catch(handleError);
return {cancel: true};
} else {
@ -654,7 +654,7 @@ function start() {
if (!browser.runtime.lastError) { // https://gitlab.com/KevinRoebert/ClearUrls/issues/346
currentURL = tab.url;
}
});
}).catch(handleError);
}
/**
@ -740,9 +740,9 @@ function increaseBadged(quiet = false) {
checkOSAndroid().then((res) => {
if (!res) {
if (storage.badgedStatus && !quiet) {
browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid});
browser.browserAction.setBadgeText({text: (++badges[tabid]).toString(), tabId: tabid}).catch(handleError);
} else {
browser.browserAction.setBadgeText({text: "", tabId: tabid});
browser.browserAction.setBadgeText({text: "", tabId: tabid}).catch(handleError);
}
}
});

View File

@ -42,7 +42,7 @@ function contextMenuStart() {
if (!results || results[0] !== true) {
return browser.tabs.executeScript(tab.id, {
file: "/external_js/clipboard-helper.js",
});
}).catch(handleError);
}
}).then(() => {
return browser.tabs.executeScript(tab.id, {

View File

@ -31,7 +31,7 @@ function resetGlobalLog(){
browser.runtime.sendMessage({
function: "setData",
params: ['log', JSON.stringify(obj)]
});
}).catch(handleError);
location.reload();
}
@ -72,7 +72,7 @@ function getLog()
"url": getDataTableTranslation()
}
} ).order([3, 'desc']).draw();
});
}).catch(handleError);
}
/**
@ -107,8 +107,8 @@ function exportGlobalLog() {
'url': URL.createObjectURL(blob),
'filename': 'ClearURLsLogExport.json',
'saveAs': true
});
});
}).catch(handleError);
}).catch(handleError);
}
/**

View File

@ -99,15 +99,15 @@ function changeSwitchButton(id, storageID)
browser.runtime.sendMessage({
function: "changeIcon",
params: []
});
}).catch(handleError);
}
changeVisibility(id, storageID);
browser.runtime.sendMessage({
function: "saveOnExit",
params: []
});
});
}).catch(handleError);
}).catch(handleError);
});
}
@ -162,17 +162,17 @@ function resetGlobalCounter(){
browser.runtime.sendMessage({
function: "setData",
params: ['globalCounter', 0]
});
}).catch(handleError);
browser.runtime.sendMessage({
function: "setData",
params: ['globalurlcounter', 0]
});
}).catch(handleError);
browser.runtime.sendMessage({
function: "saveOnExit",
params: []
});
}).catch(handleError);
globalCounter = 0;
globalurlcounter = 0;

View File

@ -107,7 +107,7 @@ function getData()
} else {
$('#logLimit_label').text(translate('setting_log_limit_label', logData.response));
}
});
}).catch(handleError);
loadData("contextMenuEnabled")
.then(() => loadData("historyListenerEnabled"))
@ -122,7 +122,7 @@ function getData()
changeSwitchButton("referralMarketing", "referralMarketing");
changeSwitchButton("domainBlocking", "domainBlocking");
changeSwitchButton("pingBlocking", "pingBlocking");
});
}).catch(handleError);
}
/**
@ -205,8 +205,8 @@ function exportSettings() {
'url': URL.createObjectURL(blob),
'filename': 'ClearURLs.conf',
'saveAs': true
});
});
}).catch(handleError);
}).catch(handleError);
}
/**
@ -262,14 +262,14 @@ function changeSwitchButton(id, storageID)
browser.runtime.sendMessage({
function: "changeIcon",
params: []
});
}).catch(handleError);
}
browser.runtime.sendMessage({
function: "saveOnExit",
params: []
});
});
}).catch(handleError);
}).catch(handleError);
});
setSwitchButton(id, storageID);
}
@ -279,7 +279,7 @@ function changeSwitchButton(id, storageID)
*
* @param {string} id ID of the HTML element
* @param {string} attribute Name of the attribute used for localization
* @param {boolean} tooltip
* @param {string} tooltip
*/
function injectText(id, attribute, tooltip = "")
{

View File

@ -75,7 +75,7 @@ function saveOnDisk(keys) {
});
console.log(translate('core_save_on_disk'));
browser.storage.local.set(json);
browser.storage.local.set(json).catch(handleError);
}
/**
@ -114,7 +114,7 @@ function genesis() {
// Start history listener
historyListenerStart();
}, error);
}, handleError);
}
/**
@ -164,14 +164,6 @@ function setData(key, value) {
}
}
/**
* Write error on console.
*/
function error(e) {
console.log(translate('core_error'));
console.error(e);
}
/**
* Set default values, if the storage is empty.
* @param {Object} items

View File

@ -235,9 +235,9 @@ function changeIcon() {
checkOSAndroid().then((res) => {
if (!res) {
if (storage.globalStatus) {
browser.browserAction.setIcon({path: "img/clearurls_128x128.png"});
browser.browserAction.setIcon({path: "img/clearurls_128x128.png"}).catch(handleError);
} else {
browser.browserAction.setIcon({path: "img/clearurls_gray_128x128.png"});
browser.browserAction.setIcon({path: "img/clearurls_gray_128x128.png"}).catch(handleError);
}
}
});
@ -252,11 +252,11 @@ function setBadgedStatus() {
checkOSAndroid().then((res) => {
if (!res && storage.badgedStatus) {
let color = storage.badged_color;
if(storage.badged_color.charAt(0) !== '#')
if (storage.badged_color.charAt(0) !== '#')
color = '#' + storage.badged_color;
browser.browserAction.setBadgeBackgroundColor({
'color': color
});
}).catch(handleError);
}
});
}
@ -294,11 +294,15 @@ function decodeURL(url) {
}
/**
* Gets the value of at `key` an object. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
*
* @param {string} key the key of the object
* @param {object} defaultValue the default value
*/
* Gets the value of at `key` an object. If the resolved value is `undefined`, the `defaultValue` is returned in its place.
*
* @param {string} key the key of the object
* @param {object} defaultValue the default value
*/
Object.prototype.getOrDefault = function (key, defaultValue) {
return this[key] === undefined ? defaultValue : this[key];
};
};
function handleError(error) {
console.log(translate('core_error') + ":" + error);
}