From 91c131a72d20691c3e43fe5a399d05c87cbbc86a Mon Sep 17 00:00:00 2001 From: Jannis Fedoruk-Betschki Date: Tue, 12 Mar 2024 19:08:26 +0100 Subject: [PATCH] Handle NoSuchKey error gracefully --- src/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index b21c277..e7713ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -196,12 +196,17 @@ class S3Storage extends StorageBase { const stream = output.Body as Readable stream.pipe(res) } catch (err) { - res.status(404) - next(err) + if (err.name === 'NoSuchKey') { + res.status(404).send('Image not found'); + } else { + res.status(500); + next(err); + } } } } + async read(options: ReadOptions = { path: '' }) { let path = (options.path || '').replace(/\/$|\\$/, '')