From e7574faeef8fece875b1f16f5e0b017f08603f42 Mon Sep 17 00:00:00 2001 From: finxol Date: Wed, 26 Jul 2023 11:20:37 +0200 Subject: [PATCH] fix(api): strong typing and error catch for image compression --- api/util/image.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/util/image.ts b/api/util/image.ts index 7312ec9e..3c1cd89d 100644 --- a/api/util/image.ts +++ b/api/util/image.ts @@ -16,12 +16,15 @@ interface DecodedImage { * @returns The compressed image. */ export async function compress(image: Buffer): Promise { - return await sharp(image) + let compressed: Buffer | void = await sharp(image) .resize(600, 600, { fit: 'inside' }) .toBuffer() .catch(err => { logger.error('Error while compressing image', err) }) + if (!compressed) + throw new Error('Error while compressing image') + return compressed as Buffer }