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={}) {
return new Promise((resolve, reject) => {
try {
chrome.runtime.sendMessage({action, params}, ({result, error}) => {
if (error) {
reject(error);
chrome.runtime.sendMessage({action, params}, (response) => {
if (response !== null && typeof response === 'object') {
if (response.error) {
reject(response.error);
} else {
resolve(result);
resolve(response.result);
}
} else {
reject(`Unexpected response of type ${typeof response}`);
}
});
} catch (e) {