mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: closes #13051, catch errors from widget render
This commit is contained in:
@@ -64,35 +64,40 @@ async function renderWidget(widget, uid, options, location) {
|
|||||||
|
|
||||||
const userLang = config.userLang || meta.config.defaultLang || 'en-GB';
|
const userLang = config.userLang || meta.config.defaultLang || 'en-GB';
|
||||||
const templateData = _.assign({ }, options.templateData, { config: config });
|
const templateData = _.assign({ }, options.templateData, { config: config });
|
||||||
const data = await plugins.hooks.fire(`filter:widget.render:${widget.widget}`, {
|
try {
|
||||||
uid: uid,
|
const data = await plugins.hooks.fire(`filter:widget.render:${widget.widget}`, {
|
||||||
area: options,
|
uid: uid,
|
||||||
templateData: templateData,
|
area: options,
|
||||||
data: widget.data,
|
templateData: templateData,
|
||||||
req: options.req,
|
data: widget.data,
|
||||||
res: options.res,
|
req: options.req,
|
||||||
location,
|
res: options.res,
|
||||||
});
|
location,
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { html } = data;
|
|
||||||
|
|
||||||
if (widget.data.container && widget.data.container.match('{body}')) {
|
|
||||||
html = await Benchpress.compileRender(widget.data.container, {
|
|
||||||
title: widget.data.title,
|
|
||||||
body: html,
|
|
||||||
template: data.templateData && data.templateData.template,
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
if (!data) {
|
||||||
if (html) {
|
return;
|
||||||
html = await translator.translate(html, userLang);
|
}
|
||||||
}
|
|
||||||
|
let { html } = data;
|
||||||
return { html };
|
|
||||||
|
if (widget.data.container && widget.data.container.match('{body}')) {
|
||||||
|
html = await Benchpress.compileRender(widget.data.container, {
|
||||||
|
title: widget.data.title,
|
||||||
|
body: html,
|
||||||
|
template: data.templateData && data.templateData.template,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (html) {
|
||||||
|
html = await translator.translate(html, userLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { html };
|
||||||
|
} catch (err) {
|
||||||
|
winston.error(err.stack);
|
||||||
|
return { html: '' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.checkVisibility = async function (data, uid) {
|
widgets.checkVisibility = async function (data, uid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user