I am using Multer to upload a maximum of 3 images to the server and it works fine, but when I upload more than 3 images, Multer tells me the error but it is not manageable to show the user.
I’m working on the route that calls the controller but in the Multer documentation it only shows how to handle errors with the route along with the controller actions.
Route:
router.post('/', upload.array('pictures', 3),
newProduct
);
Documentation code for handling Multer errors:
const multer = require('multer')
const upload = multer().single('avatar')
app.post('/profile', function (req, res) {
upload(req, res, function (err) {
if (err instanceof multer.MulterError) {
// A Multer error occurred when uploading.
} else if (err) {
// An unknown error occurred when uploading.
}
// Everything went fine.
})
})
Error response shown by Multer:
In this case how could I do the same documentation but separately to handle Multer errors?
Thank you.