more safe

This commit is contained in:
Shinigami92 2022-12-12 16:31:29 +01:00
parent a34e7e23f0
commit 26bc4e7251

View file

@ -41,6 +41,7 @@ export default defineEventHandler(async (event) => {
let ogImageUrl = ''
try {
// First we want to try to get the og:image from the html
// But sometimes it is not included due to async JS loading
const html = await $fetch<string>(cardUrl)
@ -59,5 +60,13 @@ export default defineEventHandler(async (event) => {
console.log(JSON.stringify({ cardUrl, ogImageUrl }))
await send(event, ogImageUrl)
}
catch (error) {
throw createError({
statusCode: 500,
statusMessage: (error as Error)?.message || 'Unknown error.',
cause: error,
})
}
})