Skip to content

Commit

Permalink
fix: handle unexpected errors without crashing the vite server
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Jan 14, 2022
1 parent 57b2380 commit e174936
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e174936

Please sign in to comment.