There is an image object in my AWS S3 bucket called "aws-image". When I request this image I get the object but if I request wrong object "aws-imagee" gives "Access Denied" error and crushes the node server.
What's the problem here? When I request an object that is not in the bucket I expect my server to contunie running.
const getFileStream = fileName => {
const downloadParams = {
Key: fileName,
Bucket: bucketName
}
return s3.getObject(downloadParams).createReadStream()
}
app.get('/aws-images/:id', jsonParser, (req, res) => {
const id = req.params.id
try {
const readStream = getFileStream(id)
readStream.pipe(res)
} catch (err) {
res.json(err)
}
})
Tried this try-catch block and still the "Access Denied" error of non existant object crushes the server.