Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 83168f6

Browse files
committed
Improve error reporting, handle string response from host app
1 parent 689da50 commit 83168f6

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

chrome/background.browserify.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ function onMessage(request, sender, sendResponse) {
6262
var error = chrome.runtime.lastError.message;
6363
console.error(error);
6464
sendResponse({ status: "ERROR", error: error });
65+
return;
66+
}
67+
68+
if (typeof response == "string") {
69+
console.error(response);
70+
sendResponse({ status: "ERROR", error: response });
71+
return;
6572
}
6673

6774
chrome.tabs.query({ lastFocusedWindow: true, active: true }, function(
@@ -93,6 +100,12 @@ function onMessage(request, sender, sendResponse) {
93100
return;
94101
}
95102

103+
if (typeof response == "string") {
104+
console.error(response);
105+
sendResponse({ status: "ERROR", error: response });
106+
return;
107+
}
108+
96109
let text = "";
97110
if (request.what === "password") {
98111
text = response.p;
@@ -136,6 +149,19 @@ function onMessage(request, sender, sendResponse) {
136149
app,
137150
{ action: "get", entry: request.entry, settings: getSettings() },
138151
function(response) {
152+
if (chrome.runtime.lastError) {
153+
var error = chrome.runtime.lastError.message;
154+
console.error(error);
155+
sendResponse({ status: "ERROR", error: error });
156+
return;
157+
}
158+
159+
if (typeof response == "string") {
160+
console.error(response);
161+
sendResponse({ status: "ERROR", error: response });
162+
return;
163+
}
164+
139165
if (!response.hasOwnProperty("url") || response.url.length == 0) {
140166
// guess url from login path if not available in the host app response
141167
response.url = parseUrlFromEntry(request.entry);

chrome/script.browserify.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,15 @@ function searchPassword(_domain, action = "search", useFillOnSubmit = true) {
230230
{ action: action, domain: _domain, settings: settings },
231231
function(response) {
232232
if (chrome.runtime.lastError) {
233-
error = chrome.runtime.lastError.message;
234-
console.error(error);
233+
return resetWithError(chrome.runtime.lastError.message);
235234
}
236235

237-
searching = false;
238-
239236
if (typeof response == "string") {
240-
error = response;
241-
m.redraw();
242-
return;
237+
return resetWithError(response);
243238
}
244239

240+
searching = false;
241+
245242
logins = resultLogins = response ? response : [];
246243
document.getElementById("filter-search").textContent = domain;
247244
fillOnSubmit = useFillOnSubmit && logins.length > 0;
@@ -281,7 +278,6 @@ function launchURL() {
281278
if (response.error) {
282279
return resetWithError(response.error);
283280
}
284-
285281
window.close();
286282
});
287283
}
@@ -294,15 +290,10 @@ function getLoginData() {
294290
chrome.runtime.sendMessage(
295291
{ action: "login", entry: this, urlDuringSearch: urlDuringSearch },
296292
function(response) {
297-
searching = false;
298-
fillOnSubmit = false;
299-
300293
if (response.error) {
301-
error = response.error;
302-
m.redraw();
303-
} else {
304-
window.close();
294+
return resetWithError(response.error);
305295
}
296+
window.close();
306297
}
307298
);
308299
}
@@ -312,9 +303,7 @@ function loginToClipboard() {
312303
{ action: "copyToClipboard", entry: this.entry, what: this.what },
313304
function(response) {
314305
if (response.error) {
315-
error = response.error;
316-
m.redraw();
317-
return;
306+
return resetWithError(response.error);
318307
}
319308

320309
copyToClipboard(response.text);
@@ -395,6 +384,7 @@ function oncreate() {
395384
}
396385

397386
function resetWithError(errMsg) {
387+
console.error(errMsg);
398388
domain = "";
399389
logins = resultLogins = [];
400390
fillOnSubmit = false;

0 commit comments

Comments
 (0)