From e1749363dbb4b5a984e48815f35ee5043f582f30 Mon Sep 17 00:00:00 2001 From: Maximo Mussini Date: Fri, 14 Jan 2022 11:34:32 -0300 Subject: [PATCH] fix: handle unexpected errors without crashing the vite server --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0e7b647..f88ec69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,8 +56,11 @@ export default function ImagePresetsPlugin (presets?: ImagePresets, options?: Op const image = await api.getImageById(id) - if (!image) - throw new Error(`vite-image-presets cannot find image with id "${id}" this is likely an internal error`) + if (!image) { + console.error(`vite-image-presets cannot find image with id "${id}" this is likely an internal error`) + res.statusCode = 404 + return res.end() + } res.setHeader('Content-Type', `image/${await formatFor(image)}`) res.setHeader('Cache-Control', 'max-age=360000')