Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit 6c8d7db

Browse files
author
Ke, Mingze
committed
Throw exception when happens
1 parent d34cb15 commit 6c8d7db

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

‎chrome-app/eventPage.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@
5555
} else {
5656
if (typeof obj === 'function') {
5757
params = transformParams(m, params, transReq, ctx);
58-
obj.apply(ctx, params.concat(callback));
58+
try {
59+
obj.apply(ctx, params.concat(callback));
60+
} catch (e) {
61+
portMap[senderId].postMessage({
62+
jsonrpc: '2.0',
63+
id: id,
64+
exception: e.message
65+
});
66+
}
5967
}
6068

6169
function callback() {

‎chrome-app/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "API Proxy for Google Chrome™",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"manifest_version": 2,
55
"minimum_chrome_version": "23",
66
"app": {

‎lib/chrome._api.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,23 @@ chrome._api = (function (window) {
5959
var msg = event.data;
6060

6161
if (msg.jsonrpc && !msg.method) {
62-
if (msg.error) {
63-
chrome.runtime.lastError = {
64-
message: msg.error
65-
};
66-
}
67-
68-
if (callbackHash[msg.id]) {
69-
callbackHash[msg.id].apply(undef, msg.result);
70-
delete callbackHash[msg.id];
71-
} else if (listenerHash[msg.id]) {
72-
listenerHash[msg.id].apply(undef, msg.result);
62+
if (msg.exception) {
63+
if (callbackHash[msg.id]) {
64+
delete callbackHash[msg.id];
65+
}
66+
throw new Error(msg.exception);
67+
} else {
68+
if (msg.error) {
69+
chrome.runtime.lastError = {
70+
message: msg.error
71+
};
72+
}
73+
if (callbackHash[msg.id]) {
74+
callbackHash[msg.id].apply(undef, msg.result);
75+
delete callbackHash[msg.id];
76+
} else if (listenerHash[msg.id]) {
77+
listenerHash[msg.id].apply(undef, msg.result);
78+
}
7379
}
7480
}
7581
}, false);

0 commit comments

Comments
 (0)