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,11 +196,16 @@ class S3Storage extends StorageBase {
const stream = output.Body as Readable const stream = output.Body as Readable
stream.pipe(res) stream.pipe(res)
} catch (err) { } catch (err) {
res.status(404) if (err.name === 'NoSuchKey') {
next(err) res.status(404).send('Image not found');
} else {
res.status(500);
next(err);
} }
} }
} }
}
async read(options: ReadOptions = { path: '' }) { async read(options: ReadOptions = { path: '' }) {
let path = (options.path || '').replace(/\/$|\\$/, '') let path = (options.path || '').replace(/\/$|\\$/, '')