try sendError

This commit is contained in:
Shinigami92 2022-12-12 22:41:22 +01:00
parent 49a9291339
commit 27c0c4d6f2

View file

@ -78,18 +78,26 @@ export default defineEventHandler(async (event) => {
if (!ogImageUrl.startsWith('https')) { if (!ogImageUrl.startsWith('https')) {
// If the og:image is not https, we can't use it // If the og:image is not https, we can't use it
throw createError({ sendError(event, {
statusCode: 404, // Must be 404 so the srcset can fallback to the default image statusCode: 404, // Must be 404 so the srcset can fallback to the default image
statusMessage: 'og:image must be https.', fatal: false,
message: 'og:image must be https.',
name: 'OgImageError',
unhandled: false,
}) })
return
} }
if (!ogImageUrl) { if (!ogImageUrl) {
// If nothing helped, send 404 so the srcset can fallback to the default image // If nothing helped, send 404 so the srcset can fallback to the default image
throw createError({ sendError(event, {
statusCode: 404, statusCode: 404,
statusMessage: 'Could not find og:image.', fatal: false,
message: 'Could not find og:image.',
name: 'OgImageError',
unhandled: false,
}) })
return
} }
await sendRedirect(event, ogImageUrl) await sendRedirect(event, ogImageUrl)