catch errors while building opengraph metadata to allow _some_ metadata to make it out still

This commit is contained in:
Siddharth Singh 2024-08-05 22:36:48 +05:30
parent 18e0c990e4
commit 9a96582bfc
No known key found for this signature in database

View file

@ -37,11 +37,11 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
h: 48, h: 48,
}, },
}; };
try {
if (params.acct && !params.statusId) { if (params.acct && !params.statusId) {
const profile = await getProfileInfo(params.acct); const profile = await getProfileInfo(params.acct);
res.type = 'profile'; res.type = 'profile';
res.title = `View @${await getHandle(params.acct)}'s profile on Ditto`; res.title = `View @${await getHandle(params.acct, profile.name)}'s profile on Ditto`;
res.description = profile.about; res.description = profile.about;
if (profile.picture) { if (profile.picture) {
res.image = { url: profile.picture, h: 150, w: 150 }; res.image = { url: profile.picture, h: 150, w: 150 };
@ -52,6 +52,11 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
res.image = image; res.image = image;
res.title = title; res.title = title;
} }
} catch (e) {
console.debug('Error getting OpenGraph metadata information:');
console.debug(e);
console.trace();
}
return res; return res;
} }
@ -66,7 +71,7 @@ export const frontendController: AppMiddleware = async (c, next) => {
const meta = metadataView(await buildTemplateOpts(params, Conf.local(c.req.path))); const meta = metadataView(await buildTemplateOpts(params, Conf.local(c.req.path)));
return c.html(content.replace(META_PLACEHOLDER, meta)); return c.html(content.replace(META_PLACEHOLDER, meta));
} catch (e) { } catch (e) {
console.debug(e); console.log(e);
return c.html(content); return c.html(content);
} }
} }