Skip to content

Commit

Permalink
Handle errors from sharp
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstuart committed Jul 11, 2023
1 parent 2961bc6 commit 70f6268
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
39 changes: 19 additions & 20 deletions src/server/utils/create-ssr-html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,25 @@ export async function createSsrHtml(
);

if (!appleTouchIcon) {
try {
appleTouchIcon = site?.site_view.site.icon
? `data:image/png;base64,${await sharp(
await fetchIconPng(site.site_view.site.icon)
)
.resize(180, 180)
.extend({
bottom: 20,
top: 20,
left: 20,
right: 20,
background: "#222222",
})
.png()
.toBuffer()
.then(buf => buf.toString("base64"))}`
: favIconPngUrl;
} catch (err) {
console.error(err);
}
appleTouchIcon = site?.site_view.site.icon
? `data:image/png;base64,${await sharp(
await fetchIconPng(site.site_view.site.icon)
)
.resize(180, 180)
.extend({
bottom: 20,
top: 20,
left: 20,
right: 20,
background: "#222222",
})
.png()
.toBuffer()
.then(
buf => buf.toString("base64"),
err => console.error(err)
)}`
: favIconPngUrl;
}

const erudaStr =
Expand Down
17 changes: 8 additions & 9 deletions src/server/utils/generate-manifest-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ export default async function ({
).then(buf => buf.toString("base64"));

if (icon) {
try {
src = await sharp(icon)
.resize(size, size)
.png()
.toBuffer()
.then(buf => buf.toString("base64"));
} catch (err) {
console.error(err);
}
src = await sharp(icon)
.resize(size, size)
.png()
.toBuffer()
.then(
buf => buf.toString("base64"),
err => console.error(err)
);
}

return {
Expand Down

0 comments on commit 70f6268

Please sign in to comment.