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": { "extension_description": {
"message": "Entfernt tracking Elemente von URLs.", "message": "Entfernt Tracking-Elemente von URLs.",
"description": "Erweiterungsbeschreibung (max. 132 Zeichen)" "description": "Erweiterungsbeschreibung (max. 132 Zeichen)"
}, },
"hash_status_code_1": { "hash_status_code_1": {

View File

@ -579,7 +579,7 @@ function start() {
if (result.redirect) { if (result.redirect) {
if (providers[i].shouldForceRedirect() && if (providers[i].shouldForceRedirect() &&
request.type === 'main_frame') { 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}; return {cancel: true};
} }
@ -595,7 +595,7 @@ function start() {
if (result.cancel) { if (result.cancel) {
if (request.type === 'main_frame') { if (request.type === 'main_frame') {
const blockingPage = browser.extension.getURL("html/siteBlockedAlert.html?source=" + encodeURIComponent(request.url)); 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}; return {cancel: true};
} else { } else {
@ -654,7 +654,7 @@ function start() {
if (!browser.runtime.lastError) { // https://gitlab.com/KevinRoebert/ClearUrls/issues/346 if (!browser.runtime.lastError) { // https://gitlab.com/KevinRoebert/ClearUrls/issues/346
currentURL = tab.url; currentURL = tab.url;
} }
}); }).catch(handleError);
} }
/** /**
@ -740,9 +740,9 @@ function increaseBadged(quiet = false) {
checkOSAndroid().then((res) => { checkOSAndroid().then((res) => {
if (!res) { if (!res) {
if (storage.badgedStatus && !quiet) { 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 { } 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) { if (!results || results[0] !== true) {
return browser.tabs.executeScript(tab.id, { return browser.tabs.executeScript(tab.id, {
file: "/external_js/clipboard-helper.js", file: "/external_js/clipboard-helper.js",
}); }).catch(handleError);
} }
}).then(() => { }).then(() => {
return browser.tabs.executeScript(tab.id, { return browser.tabs.executeScript(tab.id, {

View File

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

View File

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

View File

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

View File

@ -75,7 +75,7 @@ function saveOnDisk(keys) {
}); });
console.log(translate('core_save_on_disk')); 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 // Start history listener
historyListenerStart(); 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. * Set default values, if the storage is empty.
* @param {Object} items * @param {Object} items

View File

@ -235,9 +235,9 @@ function changeIcon() {
checkOSAndroid().then((res) => { checkOSAndroid().then((res) => {
if (!res) { if (!res) {
if (storage.globalStatus) { if (storage.globalStatus) {
browser.browserAction.setIcon({path: "img/clearurls_128x128.png"}); browser.browserAction.setIcon({path: "img/clearurls_128x128.png"}).catch(handleError);
} else { } 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) => { checkOSAndroid().then((res) => {
if (!res && storage.badgedStatus) { if (!res && storage.badgedStatus) {
let color = storage.badged_color; let color = storage.badged_color;
if(storage.badged_color.charAt(0) !== '#') if (storage.badged_color.charAt(0) !== '#')
color = '#' + storage.badged_color; color = '#' + storage.badged_color;
browser.browserAction.setBadgeBackgroundColor({ browser.browserAction.setBadgeBackgroundColor({
'color': color '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. * 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 {string} key the key of the object
* @param {object} defaultValue the default value * @param {object} defaultValue the default value
*/ */
Object.prototype.getOrDefault = function (key, defaultValue) { Object.prototype.getOrDefault = function (key, defaultValue) {
return this[key] === undefined ? defaultValue : this[key]; return this[key] === undefined ? defaultValue : this[key];
}; };
function handleError(error) {
console.log(translate('core_error') + ":" + error);
}