Selaa lähdekoodia

fixed error catching issue

Gildas 7 vuotta sitten
vanhempi
sitoutus
785e705053
2 muutettua tiedostoa jossa 15 lisäystä ja 11 poistoa
  1. 10 6
      lib/browser-polyfill/custom-browser-polyfill.js
  2. 5 5
      lib/fetch/bg/fetch.js

+ 10 - 6
lib/browser-polyfill/custom-browser-polyfill.js

@@ -81,12 +81,16 @@
 					addListener: listener => chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
 						const response = listener(message, sender);
 						if (response && typeof response.then == "function") {
-							response.then(response => {
-								sendResponse(response);
-								if (chrome.runtime.lastError) {
-									console.error(chrome.runtime.lastError); // eslint-disable-line no-console
-								}
-							});
+							response
+								.then(response => {
+									sendResponse(response);
+									if (chrome.runtime.lastError) {
+										console.error(chrome.runtime.lastError); // eslint-disable-line no-console
+									}
+								})
+								.catch(error => {
+									console.error(error); // eslint-disable-line no-console
+								});
 							return true;
 						}
 					}),

+ 5 - 5
lib/fetch/bg/fetch.js

@@ -28,11 +28,11 @@
 
 	browser.runtime.onMessage.addListener(request => {
 		if (request.method) {
-			try {
-				return onRequest(request);
-			} catch (error) {
-				return { error: error.toString() };
-			}
+			return new Promise((resolve, reject) => {
+				onRequest(request)
+					.then(resolve)
+					.catch(error => reject({ error: error.toString() }));
+			});
 		}
 	});