No simple way to tell the client if an error occured
See original GitHub issueAll of the error handling functions, onFileSizeLimit
, onError
etc… have no way of either telling the client that an error has happened or passing the fact an error happened to the next middle ware:
router.use('/uploads', multer({
dest: './uploads',
limits: { files: 2 },
onFilesLimit: function () {
// No way to add to the request that an error occurred, or respond to the client
}
});
router.post('/uploads', function(req, res) {
// Cannot tell that any of the limits has been reached so cannot inform the client
});
You probably don’t want to respond to the client directly when a limit has been hit, but you should at least be able to tell that an error occurred later on.
Something along the lines of:
router.use('/uploads', multer({
dest: './uploads',
limits: { files: 2 },
onFilesLimit: function (file_data) {
file_data.files_limit_reached = true;
}
});
router.post('/uploads', function(req, res) {
if (file_data.files_limit_reached) {
res.json({ error: "file limit reached" });
}
});
So that rather then removing the files that have hit an error or exceeded a limit they are flagged with an error message.
Issue Analytics
- State:
- Created 9 years ago
- Comments:18 (6 by maintainers)
Top Results From Across the Web
Best Practices for REST API Error Handling - Baeldung
The simplest way we handle errors is to respond with an appropriate status code. Here are some common response codes: ... While basic,...
Read more >Handling operation errors - Apollo GraphQL Docs
Apollo Client helps you handle these errors according to their type, enabling you to show appropriate information to the user when an error...
Read more >How To Troubleshoot Common HTTP Error Codes
This guide focuses on identifying and troubleshooting the most commonly encountered HTTP error codes, i.e. 4xx and 5xx status codes, ...
Read more >How to implement error handling in SQL Server - SQLShack
First, generally you shouldn't be "swallowing" (suppressing) errors. Inside a CATCH block, after handling the error, you should rethrow it so ...
Read more >"Cannot connect the computer to the server" error message ...
Note This issue occurs on the client computer when connecting to the server in the ... If you're not on the computer that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hi @qqilihq, I’d like to share my solution. please take a look:
After the middleware above, we can do the trick as below:
I think this might help you. One more thing might be helpful:
onFileUploadComplete
does not meansuccess
, any single file will fire this event one time, even if it runs over filesize limit.Why has
onFileSizeLimit
been removed? Is there an alternative to it that we could use?