Handle messages with unexpected response format
The response parameter can be undefined
This commit is contained in:
parent
769dc205fb
commit
c933a55b81
@ -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 {
|
} else {
|
||||||
resolve(result);
|
resolve(response.result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject(`Unexpected response of type ${typeof response}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user