Handle messages with unexpected response format

The response parameter can be undefined
This commit is contained in:
toasted-nutbread 2019-02-19 22:50:33 -05:00
parent 769dc205fb
commit c933a55b81

View File

@ -26,11 +26,15 @@ function utilAsync(func) {
function utilInvoke(action, params={}) { function utilInvoke(action, params={}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
chrome.runtime.sendMessage({action, params}, ({result, error}) => { chrome.runtime.sendMessage({action, params}, (response) => {
if (error) { if (response !== null && typeof response === 'object') {
reject(error); if (response.error) {
reject(response.error);
} else {
resolve(response.result);
}
} else { } else {
resolve(result); reject(`Unexpected response of type ${typeof response}`);
} }
}); });
} catch (e) { } catch (e) {