Skip to content

Commit

Permalink
feat: catch errors in embedded frame
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves authored Jul 30, 2024
1 parent 496328f commit 7ef3389
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ window.addEventListener("message", async function (event) {
}
const { command, args, id } = event.data;
if (command in commands) {
try {
if (command in commands === false) {
throw new Error('Invalid command: ' + command);
}
const result = await commands[command].apply(null, args);
event.source.postMessage({ event: 'success', detail: { id, result } }, event.origin);
} else {
event.source.postMessage({ event: 'error', detail: { id, error: 'Invalid command: ' + command } }, event.origin);
} catch (error) {
event.source.postMessage({ event: 'error', detail: { id, error } }, event.origin);
}
}, false);
</script>`);
Expand Down

0 comments on commit 7ef3389

Please sign in to comment.