better error handling
This commit is contained in:
parent
124ecaf824
commit
9a5a9aa47f
@ -104,7 +104,12 @@ async function apiTemplateRender(template, data, dynamic) {
|
||||
const sequence = utilBackend().sequenceNew();
|
||||
const handler = event => {
|
||||
if (event.data.sequence === sequence) {
|
||||
if (event.data.command === 'error') {
|
||||
reject(event.data.result);
|
||||
} else {
|
||||
resolve(event.data.result);
|
||||
}
|
||||
|
||||
window.removeEventListener('message', handler);
|
||||
}
|
||||
};
|
||||
|
@ -31,7 +31,16 @@ window.addEventListener('message', event => {
|
||||
window.yomichan_cache[event.data.template] = template;
|
||||
}
|
||||
|
||||
const result = template(event.data.data || {});
|
||||
event.source.postMessage({result, sequence: event.data.sequence}, '*');
|
||||
let result = null;
|
||||
let command = null;
|
||||
try {
|
||||
command = 'render';
|
||||
result = template(event.data.data || {});
|
||||
} catch (e) {
|
||||
command = 'error';
|
||||
result = e;
|
||||
}
|
||||
|
||||
event.source.postMessage({result, command, sequence: event.data.sequence}, '*');
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user