From 27c0c4d6f2e956993a29cec6b5ac8438fd563d50 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Mon, 12 Dec 2022 22:41:22 +0100 Subject: [PATCH] try sendError --- server/api/og-image/[url].ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/server/api/og-image/[url].ts b/server/api/og-image/[url].ts index 92916254..6d4bae0c 100644 --- a/server/api/og-image/[url].ts +++ b/server/api/og-image/[url].ts @@ -78,18 +78,26 @@ export default defineEventHandler(async (event) => { if (!ogImageUrl.startsWith('https')) { // 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 - statusMessage: 'og:image must be https.', + fatal: false, + message: 'og:image must be https.', + name: 'OgImageError', + unhandled: false, }) + return } if (!ogImageUrl) { // If nothing helped, send 404 so the srcset can fallback to the default image - throw createError({ + sendError(event, { 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)