Handle NoSuchKey error gracefully

This commit is contained in:
Jannis Fedoruk-Betschki 2024-03-12 19:08:26 +01:00 committed by Shibo Lyu
parent ee4bbfca75
commit 8036b3aec2

View file

@ -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(/\/$|\\$/, '')