summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-02-19 22:50:33 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-05-04 13:02:56 -0400
commitc933a55b818052c0a0922257a9fb82928723850a (patch)
tree467e1d2db7c74568daf27dcfbc66c1718cef020f /ext/fg/js
parent769dc205fb56fa8f9442f68907eb9598caea52bd (diff)
Handle messages with unexpected response format
The response parameter can be undefined
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/util.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index 5eff4018..954b3988 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -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(response.result);
+ }
} else {
- resolve(result);
+ reject(`Unexpected response of type ${typeof response}`);
}
});
} catch (e) {